Category: Matlab
Category Archives: Matlab
Make histogram for array of datetimes
I have a datetime array:
trigDatetime =
1273×1 datetime array
2024-04-30 01:15:34
2024-04-30 01:19:27
2024-04-30 02:20:49
2024-04-30 03:48:50
2024-04-30 03:49:49
How can I calculate the frequency of occurence between two dates for a bin width of an integer number of hours (1, 2, 3, 4, 6 or 12)?I have a datetime array:
trigDatetime =
1273×1 datetime array
2024-04-30 01:15:34
2024-04-30 01:19:27
2024-04-30 02:20:49
2024-04-30 03:48:50
2024-04-30 03:49:49
How can I calculate the frequency of occurence between two dates for a bin width of an integer number of hours (1, 2, 3, 4, 6 or 12)? I have a datetime array:
trigDatetime =
1273×1 datetime array
2024-04-30 01:15:34
2024-04-30 01:19:27
2024-04-30 02:20:49
2024-04-30 03:48:50
2024-04-30 03:49:49
How can I calculate the frequency of occurence between two dates for a bin width of an integer number of hours (1, 2, 3, 4, 6 or 12)? histogram, datetime MATLAB Answers — New Questions
Replacing Simscape’s gimbal joint’s Spring Stiffnes with External Torque
Hello,
I tried to understand how gimbal joint’s Spring Stiffnes work, so I tried to replace the Spring stiffness with external torque and the results are not equal.
Here is what I tried:
This is a 3D pendulum with gimbal joint. The upper gimbal joint has 3 spring with stiffnes k for all the coordinates (x,y,z). The lower gimbal joint’s spring stiffnesses are zero but there is an External torque with the value of -k*coordinate acting on the following body (this I thought would replicate the springs in the gimbal joint) as shown in the following figure.
When I simulate the pendulum such that it rotates only around one axis it works perfectly and there is 0 error between the upper and lower model. However, when I try to simulate a general motion then there is error between upper and lower model. I tried to set the external torque resolution frame both to World and Attached Frame but I just couldn’t figure out how to replicate the springs with external torque.
Do you have any idea or link to how the Springs in the gimbal joint works ? Thank you, Ondrej.Hello,
I tried to understand how gimbal joint’s Spring Stiffnes work, so I tried to replace the Spring stiffness with external torque and the results are not equal.
Here is what I tried:
This is a 3D pendulum with gimbal joint. The upper gimbal joint has 3 spring with stiffnes k for all the coordinates (x,y,z). The lower gimbal joint’s spring stiffnesses are zero but there is an External torque with the value of -k*coordinate acting on the following body (this I thought would replicate the springs in the gimbal joint) as shown in the following figure.
When I simulate the pendulum such that it rotates only around one axis it works perfectly and there is 0 error between the upper and lower model. However, when I try to simulate a general motion then there is error between upper and lower model. I tried to set the external torque resolution frame both to World and Attached Frame but I just couldn’t figure out how to replicate the springs with external torque.
Do you have any idea or link to how the Springs in the gimbal joint works ? Thank you, Ondrej. Hello,
I tried to understand how gimbal joint’s Spring Stiffnes work, so I tried to replace the Spring stiffness with external torque and the results are not equal.
Here is what I tried:
This is a 3D pendulum with gimbal joint. The upper gimbal joint has 3 spring with stiffnes k for all the coordinates (x,y,z). The lower gimbal joint’s spring stiffnesses are zero but there is an External torque with the value of -k*coordinate acting on the following body (this I thought would replicate the springs in the gimbal joint) as shown in the following figure.
When I simulate the pendulum such that it rotates only around one axis it works perfectly and there is 0 error between the upper and lower model. However, when I try to simulate a general motion then there is error between upper and lower model. I tried to set the external torque resolution frame both to World and Attached Frame but I just couldn’t figure out how to replicate the springs with external torque.
Do you have any idea or link to how the Springs in the gimbal joint works ? Thank you, Ondrej. gimbal joint, simscape, external torque and force MATLAB Answers — New Questions
Programmatically close App Designer app after running it for a unit test
I need to run mlapp myApp for a unit test, but after the test I want the app window to be closed. The only way I know to do this is to search for the app UI Figure in all graphics objects, but I feel there should be a more elegant way.
In my example there is a function appStartup that is called by myApp when the app is started, and appStartup should throw an error if the app can’t be run. My code looks like:
function testAppNotRunnable(testCase)
% code here to make sure the app can’t run
verifyError(testCase, @() myApp, "appStartup:cantRunApp") % appStartup errors when called by myApp
% close open app windows
h = findall(groot, ‘Tag’, ‘my app tag’);
close(h)
This works, but seems inelegant.I need to run mlapp myApp for a unit test, but after the test I want the app window to be closed. The only way I know to do this is to search for the app UI Figure in all graphics objects, but I feel there should be a more elegant way.
In my example there is a function appStartup that is called by myApp when the app is started, and appStartup should throw an error if the app can’t be run. My code looks like:
function testAppNotRunnable(testCase)
% code here to make sure the app can’t run
verifyError(testCase, @() myApp, "appStartup:cantRunApp") % appStartup errors when called by myApp
% close open app windows
h = findall(groot, ‘Tag’, ‘my app tag’);
close(h)
This works, but seems inelegant. I need to run mlapp myApp for a unit test, but after the test I want the app window to be closed. The only way I know to do this is to search for the app UI Figure in all graphics objects, but I feel there should be a more elegant way.
In my example there is a function appStartup that is called by myApp when the app is started, and appStartup should throw an error if the app can’t be run. My code looks like:
function testAppNotRunnable(testCase)
% code here to make sure the app can’t run
verifyError(testCase, @() myApp, "appStartup:cantRunApp") % appStartup errors when called by myApp
% close open app windows
h = findall(groot, ‘Tag’, ‘my app tag’);
close(h)
This works, but seems inelegant. appdesigner, testing MATLAB Answers — New Questions
Logitech G29 with Simulink desktop simulation
Hi
I have a logitech G29 driving wheel and pedals on PS3 mode and the simulink realtime library block for Logitech G29. Do you have any idea how can I record steering signals?
I keep on getting error though all the modules and drivers are installed in Matlab.Hi
I have a logitech G29 driving wheel and pedals on PS3 mode and the simulink realtime library block for Logitech G29. Do you have any idea how can I record steering signals?
I keep on getting error though all the modules and drivers are installed in Matlab. Hi
I have a logitech G29 driving wheel and pedals on PS3 mode and the simulink realtime library block for Logitech G29. Do you have any idea how can I record steering signals?
I keep on getting error though all the modules and drivers are installed in Matlab. logitech MATLAB Answers — New Questions
How to write this function in Matlab having inner product
Here,
inner product is defined as <u,v>=
Is this is correct?
function F_val = F(wi, ci, Li, K, e, sigma, zi)
% Compute the first term: K <e sum from i to N ci Li, e sum from i to N ci Li>
term1 = K * e^2 * sum(exp(sum(ci .* Li)) .* exp(sum(ci .* Li)));
% Compute the second term: K <e sum from i to N ci Li, -2 sigma>
term2 = K * e * sum(exp(sum(ci .* Li)) * (-2 * sigma));
% Compute the third term: summation i to N e ci <e^wi, wi>
term3 = e * sum(zi .* ci .* exp(wi));
% Compute the final result: F(w) = term1 + term2 + term3
F_val = term1 + term2 + term3;
endHere,
inner product is defined as <u,v>=
Is this is correct?
function F_val = F(wi, ci, Li, K, e, sigma, zi)
% Compute the first term: K <e sum from i to N ci Li, e sum from i to N ci Li>
term1 = K * e^2 * sum(exp(sum(ci .* Li)) .* exp(sum(ci .* Li)));
% Compute the second term: K <e sum from i to N ci Li, -2 sigma>
term2 = K * e * sum(exp(sum(ci .* Li)) * (-2 * sigma));
% Compute the third term: summation i to N e ci <e^wi, wi>
term3 = e * sum(zi .* ci .* exp(wi));
% Compute the final result: F(w) = term1 + term2 + term3
F_val = term1 + term2 + term3;
end Here,
inner product is defined as <u,v>=
Is this is correct?
function F_val = F(wi, ci, Li, K, e, sigma, zi)
% Compute the first term: K <e sum from i to N ci Li, e sum from i to N ci Li>
term1 = K * e^2 * sum(exp(sum(ci .* Li)) .* exp(sum(ci .* Li)));
% Compute the second term: K <e sum from i to N ci Li, -2 sigma>
term2 = K * e * sum(exp(sum(ci .* Li)) * (-2 * sigma));
% Compute the third term: summation i to N e ci <e^wi, wi>
term3 = e * sum(zi .* ci .* exp(wi));
% Compute the final result: F(w) = term1 + term2 + term3
F_val = term1 + term2 + term3;
end write function with inner product MATLAB Answers — New Questions
how to count a sequence of data arrays with cut off?
i have 5 data in one array. For example, the data array [2.33 2.00 1.60 1.59 1.99]. If the cutoff is 1.50, it means the amount of data is 4 (pay attention to the order of the data). the number 1.99 in the 5th index is not counted.
This is my code
cnr_all=[2.33 2.00 1.60 1.59 1.99];
cut_off=1.50;
N=zeros(size(cnr_all));
for i=1:numel(cnr_all)
if cnr_all[i] >= cut_off;
N=N+1;
break;
end
end
disp(N)i have 5 data in one array. For example, the data array [2.33 2.00 1.60 1.59 1.99]. If the cutoff is 1.50, it means the amount of data is 4 (pay attention to the order of the data). the number 1.99 in the 5th index is not counted.
This is my code
cnr_all=[2.33 2.00 1.60 1.59 1.99];
cut_off=1.50;
N=zeros(size(cnr_all));
for i=1:numel(cnr_all)
if cnr_all[i] >= cut_off;
N=N+1;
break;
end
end
disp(N) i have 5 data in one array. For example, the data array [2.33 2.00 1.60 1.59 1.99]. If the cutoff is 1.50, it means the amount of data is 4 (pay attention to the order of the data). the number 1.99 in the 5th index is not counted.
This is my code
cnr_all=[2.33 2.00 1.60 1.59 1.99];
cut_off=1.50;
N=zeros(size(cnr_all));
for i=1:numel(cnr_all)
if cnr_all[i] >= cut_off;
N=N+1;
break;
end
end
disp(N) loop, if statement, break MATLAB Answers — New Questions
Blank plot on my computer
This is my code and I was wondering why is my figure 6 empty:
https://dontpad.com/labpdsmikiThis is my code and I was wondering why is my figure 6 empty:
https://dontpad.com/labpdsmiki This is my code and I was wondering why is my figure 6 empty:
https://dontpad.com/labpdsmiki graphics MATLAB Answers — New Questions
Problem with StopRecording button
I’m using this code to record my voice, but when the recording is less than 5 seconds, the file played by the function sound is the file recorded before the last one.
This function records the voice when i push the ‘StartRecording’ button:
function StartRecording_Callback(hObject, eventdata, handles)
RecordStatus = get(hObject,’Value’);
runstr=get(hObject,’string’);
if RecordStatus == 1
% start recording
fs = 44100;
obj = audiorecorder(fs, 16, 1);
recordblocking(obj, 5);
y = getaudiodata(obj);
clear obj
save recording.mat y
else
% stop recording
StopRecording(handles);
end
This function is the callback for the function StopRecording:
function StopButton_Callback(hObject, eventdata, handles)
StopRecording(guidata(hObject));
This function saves, plays and plots the audio file:
function StopRecording(handles)
fs = 44100;
load recording y;
[filename, pathname] = uiputfile(‘*.wav’, ‘Save file name’);
cd (pathname);
audiowrite(filename, y, fs);
sound(y,fs);
handles.x = y;
handles.fs = fs;
axes(handles.axes1);
time = 0:1/fs:(length(handles.x)-1)/fs;
plot(time,handles.x);
title(‘Original Signal’);
axes(handles.axes2);
specgram(handles.x, 1024, handles.fs);
title(‘Encrypted Signal’);
I want to record, play and plot the file just created.I’m using this code to record my voice, but when the recording is less than 5 seconds, the file played by the function sound is the file recorded before the last one.
This function records the voice when i push the ‘StartRecording’ button:
function StartRecording_Callback(hObject, eventdata, handles)
RecordStatus = get(hObject,’Value’);
runstr=get(hObject,’string’);
if RecordStatus == 1
% start recording
fs = 44100;
obj = audiorecorder(fs, 16, 1);
recordblocking(obj, 5);
y = getaudiodata(obj);
clear obj
save recording.mat y
else
% stop recording
StopRecording(handles);
end
This function is the callback for the function StopRecording:
function StopButton_Callback(hObject, eventdata, handles)
StopRecording(guidata(hObject));
This function saves, plays and plots the audio file:
function StopRecording(handles)
fs = 44100;
load recording y;
[filename, pathname] = uiputfile(‘*.wav’, ‘Save file name’);
cd (pathname);
audiowrite(filename, y, fs);
sound(y,fs);
handles.x = y;
handles.fs = fs;
axes(handles.axes1);
time = 0:1/fs:(length(handles.x)-1)/fs;
plot(time,handles.x);
title(‘Original Signal’);
axes(handles.axes2);
specgram(handles.x, 1024, handles.fs);
title(‘Encrypted Signal’);
I want to record, play and plot the file just created. I’m using this code to record my voice, but when the recording is less than 5 seconds, the file played by the function sound is the file recorded before the last one.
This function records the voice when i push the ‘StartRecording’ button:
function StartRecording_Callback(hObject, eventdata, handles)
RecordStatus = get(hObject,’Value’);
runstr=get(hObject,’string’);
if RecordStatus == 1
% start recording
fs = 44100;
obj = audiorecorder(fs, 16, 1);
recordblocking(obj, 5);
y = getaudiodata(obj);
clear obj
save recording.mat y
else
% stop recording
StopRecording(handles);
end
This function is the callback for the function StopRecording:
function StopButton_Callback(hObject, eventdata, handles)
StopRecording(guidata(hObject));
This function saves, plays and plots the audio file:
function StopRecording(handles)
fs = 44100;
load recording y;
[filename, pathname] = uiputfile(‘*.wav’, ‘Save file name’);
cd (pathname);
audiowrite(filename, y, fs);
sound(y,fs);
handles.x = y;
handles.fs = fs;
axes(handles.axes1);
time = 0:1/fs:(length(handles.x)-1)/fs;
plot(time,handles.x);
title(‘Original Signal’);
axes(handles.axes2);
specgram(handles.x, 1024, handles.fs);
title(‘Encrypted Signal’);
I want to record, play and plot the file just created. sound, audiowrite, audiorecorder MATLAB Answers — New Questions
Why is my script not detecting changes in UI?
Hi all! I am relatively new to app design in Matlab and I’m trying to design an app for an automated recording set-up. The idea is that users can define metadata in the UI (animal ID, duration of trial, etc.) before starting the session, then start and pause the session as needed, and then monitor the recording from the app while the automation is controlled in a separate matlab script (i.e. the automation is not running on the callbacks). I can get my app to pass information back to the base script using assignin for basic inputs and pass data back to the UI for monitoring like a timer and temperature. However, I can’t figure out how to execute my code only when the user starts the trial. To start with something simple, I have written an UpdateTimer function that updates the timer when called in the main script (I had originally written a timer into the callback but then nothing else can run so now the user will see the timer update everytime something runs in the automation to approximate the time since starting) and I have some dummy temperature data. When the user clicks Start on the UI, I would like the timer and temperature to update every 10 seconds. However, no matter what I try, the script can’t tell when the button has changed. Can anyone help me??
Main Script:
clear all;
close all;
b1_State = ‘NotStarted’; %Initial state of start button
Box1 = TestApp; %Calling UI
%pause(15); %I can pause is for 15seconds and quickly enter everything and then hit start and the following will work, but I don’t want the user to be on a time limit before starting the session
switch b1_State %This was the last thing I tried, I’ve also tried while and if loops with no success either
case ‘Recording’
test = 5;
Box1.Timer_EditField.Value = UpdateTimer(b1_StartTime, b1_PauseTime, b1_Duration, Box1);
Box1.TemperatureCEditField.Value = num2str(25);
pause(10)
Box1.Timer_EditField.Value = UpdateTimer(b1_StartTime, b1_PauseTime, b1_Duration, Box1);
Box1.TemperatureCEditField.Value = num2str(35);
end % Eventually I will specify what happens when the script is paused, but I just wanted to get one case working first
UpdateTimer Script (Note I’m still working on what happens if the user pauses and then continues the recording):
function update = UpdateTimer(StartTime, PauseTime, Duration, Box)
Now = datestr(now, "HH:MM:SS.FFF");
Now_H = str2double(Now(1:2));
Now_M = str2double(Now(4:5));
Now_S = str2double(Now(7:12)) + Now_M*60 + Now_H*3600;
Start_H = str2double(StartTime(1:2));
Start_M = str2double(StartTime(4:5));
Start_S = str2double(StartTime(7:12)) + Start_M*60 + Start_H*3600;
Update_S = Now_S – Start_S;
if Update_S < Duration*60
A(1) = floor(Update_S/3600);
A(2) = floor((Update_S – A(1)*3600)/60);
A(3) = Update_S – A(1)*3600 – A(2)*60;
update = sprintf(‘%02.0f:%02.0f:%02.3f’, A(1), A(2), A(3));
else
Box.Timer_EditField.Value = ‘Session Over’;
Box.PAUSEButton.Text = ‘END’;
Box.PAUSEButton.BackgroundColor = ‘Red’;
Box.LampColor = ‘#9aa0a2’;
Box.STARTButton.Text = ‘START’;
end
UI Script Attached if needed!
Thank you SO much in advance for any guidance!!Hi all! I am relatively new to app design in Matlab and I’m trying to design an app for an automated recording set-up. The idea is that users can define metadata in the UI (animal ID, duration of trial, etc.) before starting the session, then start and pause the session as needed, and then monitor the recording from the app while the automation is controlled in a separate matlab script (i.e. the automation is not running on the callbacks). I can get my app to pass information back to the base script using assignin for basic inputs and pass data back to the UI for monitoring like a timer and temperature. However, I can’t figure out how to execute my code only when the user starts the trial. To start with something simple, I have written an UpdateTimer function that updates the timer when called in the main script (I had originally written a timer into the callback but then nothing else can run so now the user will see the timer update everytime something runs in the automation to approximate the time since starting) and I have some dummy temperature data. When the user clicks Start on the UI, I would like the timer and temperature to update every 10 seconds. However, no matter what I try, the script can’t tell when the button has changed. Can anyone help me??
Main Script:
clear all;
close all;
b1_State = ‘NotStarted’; %Initial state of start button
Box1 = TestApp; %Calling UI
%pause(15); %I can pause is for 15seconds and quickly enter everything and then hit start and the following will work, but I don’t want the user to be on a time limit before starting the session
switch b1_State %This was the last thing I tried, I’ve also tried while and if loops with no success either
case ‘Recording’
test = 5;
Box1.Timer_EditField.Value = UpdateTimer(b1_StartTime, b1_PauseTime, b1_Duration, Box1);
Box1.TemperatureCEditField.Value = num2str(25);
pause(10)
Box1.Timer_EditField.Value = UpdateTimer(b1_StartTime, b1_PauseTime, b1_Duration, Box1);
Box1.TemperatureCEditField.Value = num2str(35);
end % Eventually I will specify what happens when the script is paused, but I just wanted to get one case working first
UpdateTimer Script (Note I’m still working on what happens if the user pauses and then continues the recording):
function update = UpdateTimer(StartTime, PauseTime, Duration, Box)
Now = datestr(now, "HH:MM:SS.FFF");
Now_H = str2double(Now(1:2));
Now_M = str2double(Now(4:5));
Now_S = str2double(Now(7:12)) + Now_M*60 + Now_H*3600;
Start_H = str2double(StartTime(1:2));
Start_M = str2double(StartTime(4:5));
Start_S = str2double(StartTime(7:12)) + Start_M*60 + Start_H*3600;
Update_S = Now_S – Start_S;
if Update_S < Duration*60
A(1) = floor(Update_S/3600);
A(2) = floor((Update_S – A(1)*3600)/60);
A(3) = Update_S – A(1)*3600 – A(2)*60;
update = sprintf(‘%02.0f:%02.0f:%02.3f’, A(1), A(2), A(3));
else
Box.Timer_EditField.Value = ‘Session Over’;
Box.PAUSEButton.Text = ‘END’;
Box.PAUSEButton.BackgroundColor = ‘Red’;
Box.LampColor = ‘#9aa0a2’;
Box.STARTButton.Text = ‘START’;
end
UI Script Attached if needed!
Thank you SO much in advance for any guidance!! Hi all! I am relatively new to app design in Matlab and I’m trying to design an app for an automated recording set-up. The idea is that users can define metadata in the UI (animal ID, duration of trial, etc.) before starting the session, then start and pause the session as needed, and then monitor the recording from the app while the automation is controlled in a separate matlab script (i.e. the automation is not running on the callbacks). I can get my app to pass information back to the base script using assignin for basic inputs and pass data back to the UI for monitoring like a timer and temperature. However, I can’t figure out how to execute my code only when the user starts the trial. To start with something simple, I have written an UpdateTimer function that updates the timer when called in the main script (I had originally written a timer into the callback but then nothing else can run so now the user will see the timer update everytime something runs in the automation to approximate the time since starting) and I have some dummy temperature data. When the user clicks Start on the UI, I would like the timer and temperature to update every 10 seconds. However, no matter what I try, the script can’t tell when the button has changed. Can anyone help me??
Main Script:
clear all;
close all;
b1_State = ‘NotStarted’; %Initial state of start button
Box1 = TestApp; %Calling UI
%pause(15); %I can pause is for 15seconds and quickly enter everything and then hit start and the following will work, but I don’t want the user to be on a time limit before starting the session
switch b1_State %This was the last thing I tried, I’ve also tried while and if loops with no success either
case ‘Recording’
test = 5;
Box1.Timer_EditField.Value = UpdateTimer(b1_StartTime, b1_PauseTime, b1_Duration, Box1);
Box1.TemperatureCEditField.Value = num2str(25);
pause(10)
Box1.Timer_EditField.Value = UpdateTimer(b1_StartTime, b1_PauseTime, b1_Duration, Box1);
Box1.TemperatureCEditField.Value = num2str(35);
end % Eventually I will specify what happens when the script is paused, but I just wanted to get one case working first
UpdateTimer Script (Note I’m still working on what happens if the user pauses and then continues the recording):
function update = UpdateTimer(StartTime, PauseTime, Duration, Box)
Now = datestr(now, "HH:MM:SS.FFF");
Now_H = str2double(Now(1:2));
Now_M = str2double(Now(4:5));
Now_S = str2double(Now(7:12)) + Now_M*60 + Now_H*3600;
Start_H = str2double(StartTime(1:2));
Start_M = str2double(StartTime(4:5));
Start_S = str2double(StartTime(7:12)) + Start_M*60 + Start_H*3600;
Update_S = Now_S – Start_S;
if Update_S < Duration*60
A(1) = floor(Update_S/3600);
A(2) = floor((Update_S – A(1)*3600)/60);
A(3) = Update_S – A(1)*3600 – A(2)*60;
update = sprintf(‘%02.0f:%02.0f:%02.3f’, A(1), A(2), A(3));
else
Box.Timer_EditField.Value = ‘Session Over’;
Box.PAUSEButton.Text = ‘END’;
Box.PAUSEButton.BackgroundColor = ‘Red’;
Box.LampColor = ‘#9aa0a2’;
Box.STARTButton.Text = ‘START’;
end
UI Script Attached if needed!
Thank you SO much in advance for any guidance!! appdesigner, userinterface MATLAB Answers — New Questions
How do I make this code a global one, which works for different pictures associated with skin wounds?
clear all
close all
[Im,map] = imread("rana2.jpg");
imshow(Im,map)
ImBgnd = rgb2gray(Im)
ImBgnd = double(ImBgnd)/255
[ImH,ImS,ImV] = ConversieHSV(Im);
%Conversie HSV
imshow(ImH/360)
imshow(ImS/100)
imshow(ImV/100)
ImBinarHS = Filtrare(ImH,350,5);
ImBinarHSf = imfill(ImBinarHS,"holes");
imshow(ImBinarHSf)
Imfinal = Im.*uint8(ImBinarHSf);
imshow(Imfinal)
ImBinarVS = Filtrare(ImS,70,35);
ImBinarVS = ~ImBinarVS;
ImBinarVSf = imfill(ImBinarVS,"holes");
imshow(ImBinarVS)
Imfinal = Im.*uint8(ImBinarVSf);
imshow(Imfinal)
ImfinS = ImBinarHSf&ImBinarVSf;
Imfinal = Im.*uint8(~ImfinS);
imshow(Imfinal)
[ImH,ImS,ImV] = ConversieHSV(Im);
imshow(ImH/360)
imshow(ImS/100)
imshow(ImV/100)
ImBinarHI = Filtrare(ImH,10,1);
ImBinarHIf = imfill(ImBinarHI,"holes");
imshow(ImBinarHIf)
Label = bwlabel(ImBinarHIf)
Label(Label~=1) = 0;
Label = ~Label
Imfinal = Im.*uint8(ImBinarHIf);
imshow(Imfinal)
ImBinarVI = Filtrare(ImS,70,35);
ImBinarVI = ~ImBinarVI;
ImBinarVIf = imfill(ImBinarVI,"holes");
imshow(ImBinarVI)
Imfinal = Im.*uint8(ImBinarVIf);
imshow(Imfinal)
ImfinI = ImBinarHIf&ImBinarVIf&Label;
ImfinI = ImfinI-ImfinS;
ImfinI = imclearborder(ImfinI);
Imfinal = Im.*uint8(~ImfinI);
imshow(Imfinal);
ImfinalIS = ImfinI|ImfinS;
ImfinalP = ~ImfinalIS;
ImFinalI(:,:,1) = ImBgnd.*(ImfinI*255)/255;
ImFinalI(:,:,2) = ImBgnd.*(ImfinI*0)/255;
ImFinalI(:,:,3) = ImBgnd.*(ImfinI*0)/255;
ImFinalS(:,:,1) = ImBgnd.*(ImfinS*100)/255;
ImFinalS(:,:,2) = ImBgnd.*(ImfinS*100)/255;
ImFinalS(:,:,3) = ImBgnd.*(ImfinS*100)/255;
ImFinalP(:,:,1) = ImBgnd.*(ImfinalP*0)/255;
ImFinalP(:,:,2) = ImBgnd.*(ImfinalP*255)/255;
ImFinalP(:,:,3) = ImBgnd.*(ImfinalP*0)/255;
ImfinalIS = Im.*uint8(~ImfinalIS);
Imfinal = ImFinalP+ImFinalI+ImFinalS
imshow(Imfinal)
imshowpair(Im,Imfinal,"montage")
%this is what i did wrong, this is not global
%
%and this is what i realised for this photo, this was the original photo, for this i made the code
%
%i need to help me if you can, i need to do this code global for mode photoes for my graduation, but i dont know how to continue, thank you guys!clear all
close all
[Im,map] = imread("rana2.jpg");
imshow(Im,map)
ImBgnd = rgb2gray(Im)
ImBgnd = double(ImBgnd)/255
[ImH,ImS,ImV] = ConversieHSV(Im);
%Conversie HSV
imshow(ImH/360)
imshow(ImS/100)
imshow(ImV/100)
ImBinarHS = Filtrare(ImH,350,5);
ImBinarHSf = imfill(ImBinarHS,"holes");
imshow(ImBinarHSf)
Imfinal = Im.*uint8(ImBinarHSf);
imshow(Imfinal)
ImBinarVS = Filtrare(ImS,70,35);
ImBinarVS = ~ImBinarVS;
ImBinarVSf = imfill(ImBinarVS,"holes");
imshow(ImBinarVS)
Imfinal = Im.*uint8(ImBinarVSf);
imshow(Imfinal)
ImfinS = ImBinarHSf&ImBinarVSf;
Imfinal = Im.*uint8(~ImfinS);
imshow(Imfinal)
[ImH,ImS,ImV] = ConversieHSV(Im);
imshow(ImH/360)
imshow(ImS/100)
imshow(ImV/100)
ImBinarHI = Filtrare(ImH,10,1);
ImBinarHIf = imfill(ImBinarHI,"holes");
imshow(ImBinarHIf)
Label = bwlabel(ImBinarHIf)
Label(Label~=1) = 0;
Label = ~Label
Imfinal = Im.*uint8(ImBinarHIf);
imshow(Imfinal)
ImBinarVI = Filtrare(ImS,70,35);
ImBinarVI = ~ImBinarVI;
ImBinarVIf = imfill(ImBinarVI,"holes");
imshow(ImBinarVI)
Imfinal = Im.*uint8(ImBinarVIf);
imshow(Imfinal)
ImfinI = ImBinarHIf&ImBinarVIf&Label;
ImfinI = ImfinI-ImfinS;
ImfinI = imclearborder(ImfinI);
Imfinal = Im.*uint8(~ImfinI);
imshow(Imfinal);
ImfinalIS = ImfinI|ImfinS;
ImfinalP = ~ImfinalIS;
ImFinalI(:,:,1) = ImBgnd.*(ImfinI*255)/255;
ImFinalI(:,:,2) = ImBgnd.*(ImfinI*0)/255;
ImFinalI(:,:,3) = ImBgnd.*(ImfinI*0)/255;
ImFinalS(:,:,1) = ImBgnd.*(ImfinS*100)/255;
ImFinalS(:,:,2) = ImBgnd.*(ImfinS*100)/255;
ImFinalS(:,:,3) = ImBgnd.*(ImfinS*100)/255;
ImFinalP(:,:,1) = ImBgnd.*(ImfinalP*0)/255;
ImFinalP(:,:,2) = ImBgnd.*(ImfinalP*255)/255;
ImFinalP(:,:,3) = ImBgnd.*(ImfinalP*0)/255;
ImfinalIS = Im.*uint8(~ImfinalIS);
Imfinal = ImFinalP+ImFinalI+ImFinalS
imshow(Imfinal)
imshowpair(Im,Imfinal,"montage")
%this is what i did wrong, this is not global
%
%and this is what i realised for this photo, this was the original photo, for this i made the code
%
%i need to help me if you can, i need to do this code global for mode photoes for my graduation, but i dont know how to continue, thank you guys! clear all
close all
[Im,map] = imread("rana2.jpg");
imshow(Im,map)
ImBgnd = rgb2gray(Im)
ImBgnd = double(ImBgnd)/255
[ImH,ImS,ImV] = ConversieHSV(Im);
%Conversie HSV
imshow(ImH/360)
imshow(ImS/100)
imshow(ImV/100)
ImBinarHS = Filtrare(ImH,350,5);
ImBinarHSf = imfill(ImBinarHS,"holes");
imshow(ImBinarHSf)
Imfinal = Im.*uint8(ImBinarHSf);
imshow(Imfinal)
ImBinarVS = Filtrare(ImS,70,35);
ImBinarVS = ~ImBinarVS;
ImBinarVSf = imfill(ImBinarVS,"holes");
imshow(ImBinarVS)
Imfinal = Im.*uint8(ImBinarVSf);
imshow(Imfinal)
ImfinS = ImBinarHSf&ImBinarVSf;
Imfinal = Im.*uint8(~ImfinS);
imshow(Imfinal)
[ImH,ImS,ImV] = ConversieHSV(Im);
imshow(ImH/360)
imshow(ImS/100)
imshow(ImV/100)
ImBinarHI = Filtrare(ImH,10,1);
ImBinarHIf = imfill(ImBinarHI,"holes");
imshow(ImBinarHIf)
Label = bwlabel(ImBinarHIf)
Label(Label~=1) = 0;
Label = ~Label
Imfinal = Im.*uint8(ImBinarHIf);
imshow(Imfinal)
ImBinarVI = Filtrare(ImS,70,35);
ImBinarVI = ~ImBinarVI;
ImBinarVIf = imfill(ImBinarVI,"holes");
imshow(ImBinarVI)
Imfinal = Im.*uint8(ImBinarVIf);
imshow(Imfinal)
ImfinI = ImBinarHIf&ImBinarVIf&Label;
ImfinI = ImfinI-ImfinS;
ImfinI = imclearborder(ImfinI);
Imfinal = Im.*uint8(~ImfinI);
imshow(Imfinal);
ImfinalIS = ImfinI|ImfinS;
ImfinalP = ~ImfinalIS;
ImFinalI(:,:,1) = ImBgnd.*(ImfinI*255)/255;
ImFinalI(:,:,2) = ImBgnd.*(ImfinI*0)/255;
ImFinalI(:,:,3) = ImBgnd.*(ImfinI*0)/255;
ImFinalS(:,:,1) = ImBgnd.*(ImfinS*100)/255;
ImFinalS(:,:,2) = ImBgnd.*(ImfinS*100)/255;
ImFinalS(:,:,3) = ImBgnd.*(ImfinS*100)/255;
ImFinalP(:,:,1) = ImBgnd.*(ImfinalP*0)/255;
ImFinalP(:,:,2) = ImBgnd.*(ImfinalP*255)/255;
ImFinalP(:,:,3) = ImBgnd.*(ImfinalP*0)/255;
ImfinalIS = Im.*uint8(~ImfinalIS);
Imfinal = ImFinalP+ImFinalI+ImFinalS
imshow(Imfinal)
imshowpair(Im,Imfinal,"montage")
%this is what i did wrong, this is not global
%
%and this is what i realised for this photo, this was the original photo, for this i made the code
%
%i need to help me if you can, i need to do this code global for mode photoes for my graduation, but i dont know how to continue, thank you guys! image processing, filter, choose file to process MATLAB Answers — New Questions
Changing a Drop Down component items via a string.
Hi all,
I am making a GUI for my XML files. The problem is related to a Drop Down component. As shown in the picture:
In the last column (option) and second row, a 1×6 string exist. Here is ther problem. When I manually define a 1×6 string array using the code bellow:
B = ["Red","Yellow","Blue","Green"];
I can change component’s items. But, when I use the bellow opcode:
inStruct.input.group.group(1).param(2).option
An error emerges!
Anyway, my question is how it is possible to change my drop down menu items by the items included in the second row and last column?
TNX.Hi all,
I am making a GUI for my XML files. The problem is related to a Drop Down component. As shown in the picture:
In the last column (option) and second row, a 1×6 string exist. Here is ther problem. When I manually define a 1×6 string array using the code bellow:
B = ["Red","Yellow","Blue","Green"];
I can change component’s items. But, when I use the bellow opcode:
inStruct.input.group.group(1).param(2).option
An error emerges!
Anyway, my question is how it is possible to change my drop down menu items by the items included in the second row and last column?
TNX. Hi all,
I am making a GUI for my XML files. The problem is related to a Drop Down component. As shown in the picture:
In the last column (option) and second row, a 1×6 string exist. Here is ther problem. When I manually define a 1×6 string array using the code bellow:
B = ["Red","Yellow","Blue","Green"];
I can change component’s items. But, when I use the bellow opcode:
inStruct.input.group.group(1).param(2).option
An error emerges!
Anyway, my question is how it is possible to change my drop down menu items by the items included in the second row and last column?
TNX. xml, gui MATLAB Answers — New Questions
Error in building C++ shared Library
I am getting this error, when I am building cpp shared library with dlls.
Building with ‘Microsoft Visual C++ 2017’
LINK: fatal error LNK1181: cannot open inputt file ‘gdi32.lib’
Error using compiler.internal.build.builder.Generic/build
The following command:
""C:Program FilesMATLABR2023abinmbuild" -client mbuild -O -output "mwa_Addmatrix" -I".mwa_AddmatrixcppSharedLibrary"
".mwa_AddmatrixcppSharedLibrarymwa_Addmatrix.cpp" DEFFILE"="".mwa_AddmatrixcppSharedLibrarymwa_Addmatrix.def""" LINKEXPORT"=""/DLL
/def:"$DEFFILE"""" LDEXT"="".dll""" LDTYPE"="" -shared -static""" MTCMDLINE"=""mt -outputresource:$EXE;2 -manifest $MANIFEST""" -outdir
".mwa_AddmatrixcppSharedLibrary""
failed with error code -1.
Error in compiler.build.cppSharedLibrary (line 115)
resultsobj = builder.build;I am getting this error, when I am building cpp shared library with dlls.
Building with ‘Microsoft Visual C++ 2017’
LINK: fatal error LNK1181: cannot open inputt file ‘gdi32.lib’
Error using compiler.internal.build.builder.Generic/build
The following command:
""C:Program FilesMATLABR2023abinmbuild" -client mbuild -O -output "mwa_Addmatrix" -I".mwa_AddmatrixcppSharedLibrary"
".mwa_AddmatrixcppSharedLibrarymwa_Addmatrix.cpp" DEFFILE"="".mwa_AddmatrixcppSharedLibrarymwa_Addmatrix.def""" LINKEXPORT"=""/DLL
/def:"$DEFFILE"""" LDEXT"="".dll""" LDTYPE"="" -shared -static""" MTCMDLINE"=""mt -outputresource:$EXE;2 -manifest $MANIFEST""" -outdir
".mwa_AddmatrixcppSharedLibrary""
failed with error code -1.
Error in compiler.build.cppSharedLibrary (line 115)
resultsobj = builder.build; I am getting this error, when I am building cpp shared library with dlls.
Building with ‘Microsoft Visual C++ 2017’
LINK: fatal error LNK1181: cannot open inputt file ‘gdi32.lib’
Error using compiler.internal.build.builder.Generic/build
The following command:
""C:Program FilesMATLABR2023abinmbuild" -client mbuild -O -output "mwa_Addmatrix" -I".mwa_AddmatrixcppSharedLibrary"
".mwa_AddmatrixcppSharedLibrarymwa_Addmatrix.cpp" DEFFILE"="".mwa_AddmatrixcppSharedLibrarymwa_Addmatrix.def""" LINKEXPORT"=""/DLL
/def:"$DEFFILE"""" LDEXT"="".dll""" LDTYPE"="" -shared -static""" MTCMDLINE"=""mt -outputresource:$EXE;2 -manifest $MANIFEST""" -outdir
".mwa_AddmatrixcppSharedLibrary""
failed with error code -1.
Error in compiler.build.cppSharedLibrary (line 115)
resultsobj = builder.build; cpp shared library, cpp, matlab, dll, compiler, sharedlibrary, library compiler, c++ MATLAB Answers — New Questions
Library compiler Error while packaging MATLAB functions into a C++ library and create a Dynamic Linking Library (DLL)
I am converting MATLAB functions into a C++ library and create a Dynamic Linking Library (DLL) using LIbrary Compiler. I am using Matlab 2023a and Microsoft Visual Studio 2017. It was working fine. But when I formatted the system and reinstalled everything, it is giving the following error while packaging-
""C:Program FilesMATLABR2023abinmbuild" -client mbuild -O -v -output "test" -I"D:SCATTER_CORRECTIONkernel_basedsc_dll_thoraxtestfor_testing" "D:SCATTER_CORRECTIONkernel_basedsc_dll_thoraxtestfor_testingtest.cpp" DEFFILE"=""D:SCATTER_CORRECTIONkernel_basedsc_dll_thoraxtestfor_testingtest.def""" LINKEXPORT"=""/DLL /def:"$DEFFILE"""" LDEXT"="".dll""" LDTYPE"="" -shared -static""" MTCMDLINE"=""mt -outputresource:$EXE;2 -manifest $MANIFEST""" -outdir "D:SCATTER_CORRECTIONkernel_basedsc_dll_thoraxtestfor_testing""
failed with error code -1.
mcc failed
Please suggest, where am I going wrong.I am converting MATLAB functions into a C++ library and create a Dynamic Linking Library (DLL) using LIbrary Compiler. I am using Matlab 2023a and Microsoft Visual Studio 2017. It was working fine. But when I formatted the system and reinstalled everything, it is giving the following error while packaging-
""C:Program FilesMATLABR2023abinmbuild" -client mbuild -O -v -output "test" -I"D:SCATTER_CORRECTIONkernel_basedsc_dll_thoraxtestfor_testing" "D:SCATTER_CORRECTIONkernel_basedsc_dll_thoraxtestfor_testingtest.cpp" DEFFILE"=""D:SCATTER_CORRECTIONkernel_basedsc_dll_thoraxtestfor_testingtest.def""" LINKEXPORT"=""/DLL /def:"$DEFFILE"""" LDEXT"="".dll""" LDTYPE"="" -shared -static""" MTCMDLINE"=""mt -outputresource:$EXE;2 -manifest $MANIFEST""" -outdir "D:SCATTER_CORRECTIONkernel_basedsc_dll_thoraxtestfor_testing""
failed with error code -1.
mcc failed
Please suggest, where am I going wrong. I am converting MATLAB functions into a C++ library and create a Dynamic Linking Library (DLL) using LIbrary Compiler. I am using Matlab 2023a and Microsoft Visual Studio 2017. It was working fine. But when I formatted the system and reinstalled everything, it is giving the following error while packaging-
""C:Program FilesMATLABR2023abinmbuild" -client mbuild -O -v -output "test" -I"D:SCATTER_CORRECTIONkernel_basedsc_dll_thoraxtestfor_testing" "D:SCATTER_CORRECTIONkernel_basedsc_dll_thoraxtestfor_testingtest.cpp" DEFFILE"=""D:SCATTER_CORRECTIONkernel_basedsc_dll_thoraxtestfor_testingtest.def""" LINKEXPORT"=""/DLL /def:"$DEFFILE"""" LDEXT"="".dll""" LDTYPE"="" -shared -static""" MTCMDLINE"=""mt -outputresource:$EXE;2 -manifest $MANIFEST""" -outdir "D:SCATTER_CORRECTIONkernel_basedsc_dll_thoraxtestfor_testing""
failed with error code -1.
mcc failed
Please suggest, where am I going wrong. library compiler, dll, c++ shared library, matlab compiler, embedded matlab function, compiler, application compiler, cpp MATLAB Answers — New Questions
Installing standalone .exe application using matlab runtime installer.
I have packaged a standalone application using Matlab Compiler(R2020a). At that time, I did not have option to choose the matlab runtime version with which I want to package my application. Is it possible to install an app packaged with matlab runtime 9.8 in another device which has matlab runtime 9.4? if not is there any other way to do it??I have packaged a standalone application using Matlab Compiler(R2020a). At that time, I did not have option to choose the matlab runtime version with which I want to package my application. Is it possible to install an app packaged with matlab runtime 9.8 in another device which has matlab runtime 9.4? if not is there any other way to do it?? I have packaged a standalone application using Matlab Compiler(R2020a). At that time, I did not have option to choose the matlab runtime version with which I want to package my application. Is it possible to install an app packaged with matlab runtime 9.8 in another device which has matlab runtime 9.4? if not is there any other way to do it?? matlab compiler, matlab gui MATLAB Answers — New Questions
Need help on an error regarding a Simulink model
I have a ongoing study on a model regarding insulation coordination which I downloaded from this link https://www.mathworks.com/matlabcentral/fileexchange/108549-insulation-coordination-in-a-generating-station/?s_tid=LandingPageTabfx, it shows an error when I tried to run the model. Not sure what I’m doing wrong, hoping for a solution.
I have attached the original file(project1F30X2_m) and a slightly modified version(model2).
Error Encountered: Specialized Power Systems cannot solve this circuit. Please check for one the following two possibilities : 1) The circuit solution is undetermined. This problem arises when transformers with no magnetization branch (Rm=inf; Lm=inf) are connected together. –> Specify a magnetizing branch with finite Rm and/or Lm parameter values. 2) Circuit solution is inuccurate due to a badly scaled circuit. This is usually caused by a too wide range of resistance values (ex 1e-6 ohm and 1e6 ohm in the same circuit). –> Try to reduce range of resistance values. For example, reduce snubber resistances.I have a ongoing study on a model regarding insulation coordination which I downloaded from this link https://www.mathworks.com/matlabcentral/fileexchange/108549-insulation-coordination-in-a-generating-station/?s_tid=LandingPageTabfx, it shows an error when I tried to run the model. Not sure what I’m doing wrong, hoping for a solution.
I have attached the original file(project1F30X2_m) and a slightly modified version(model2).
Error Encountered: Specialized Power Systems cannot solve this circuit. Please check for one the following two possibilities : 1) The circuit solution is undetermined. This problem arises when transformers with no magnetization branch (Rm=inf; Lm=inf) are connected together. –> Specify a magnetizing branch with finite Rm and/or Lm parameter values. 2) Circuit solution is inuccurate due to a badly scaled circuit. This is usually caused by a too wide range of resistance values (ex 1e-6 ohm and 1e6 ohm in the same circuit). –> Try to reduce range of resistance values. For example, reduce snubber resistances. I have a ongoing study on a model regarding insulation coordination which I downloaded from this link https://www.mathworks.com/matlabcentral/fileexchange/108549-insulation-coordination-in-a-generating-station/?s_tid=LandingPageTabfx, it shows an error when I tried to run the model. Not sure what I’m doing wrong, hoping for a solution.
I have attached the original file(project1F30X2_m) and a slightly modified version(model2).
Error Encountered: Specialized Power Systems cannot solve this circuit. Please check for one the following two possibilities : 1) The circuit solution is undetermined. This problem arises when transformers with no magnetization branch (Rm=inf; Lm=inf) are connected together. –> Specify a magnetizing branch with finite Rm and/or Lm parameter values. 2) Circuit solution is inuccurate due to a badly scaled circuit. This is usually caused by a too wide range of resistance values (ex 1e-6 ohm and 1e6 ohm in the same circuit). –> Try to reduce range of resistance values. For example, reduce snubber resistances. error MATLAB Answers — New Questions
Parameter Identification with PINN (Physics Informed NN)
Hello,
I have a system of PDEs simulating a heat transfer system, and I have experimental data of the behaviour of the system. I am trying to use a PINN for the identification of 4 unkwnon parameters.
I am trying first to validate the model with known parameters, but I am unable to reach any reasonable parameter value. The learning rate is too slow, any recommendations?
Thanks for the help!
To run the code you will need to download the following .mat: https://cyclomed-my.sharepoint.com/:u:/g/personal/administracion_cyclomed_onmicrosoft_com/ETlg6E6520JDnBoIOv35Bq0B0o6ZCXvAvvqG3Gn1Ht3ssA?e=hKclKH
For context this is a simplified version of the PDE:
% Identify parameters of single blow equation
% 1) Fluid (u1) –> B*du1/dt + du1/dx = 1/Pe*d2u1/dx^2 + NTU*(u2 – u1) + NTU_W(u3 – u1)
% 2) Regenerator (u2) –>du2/dx = K_R*d2u2/dx^2 – NTU*(u2 – u1)
% 3) Wall (u3) –> du3/dx = R_TC*K_W*d2u3/dx^2 – R_TC*NTU_W*(u3 – u1) – NTU_W(u3 – u3_init)
% Load Experiment data
load("Test 11.mat");
%% Neural Network Definition
batchSize = 500;
dimension = 2; % X = (t,x)
% Set up neural net.
hiddenSize = 100;
net = [
featureInputLayer(dimension)
fullyConnectedLayer(hiddenSize)
tanhLayer
fullyConnectedLayer(hiddenSize)
tanhLayer
fullyConnectedLayer(hiddenSize)
tanhLayer
fullyConnectedLayer(3)];
% Create struct of parameters
parameters.net = dlnetwork(net);
% Unknown PDE parameters
parameters.Pe = dlarray(1000);
parameters.NTU = dlarray(200);
parameters.NTU_W = dlarray(1);
parameters.NTU_EXT = dlarray(50);
% Known PDE parameters
constants.B = B;
constants.K_R = K_R;
constants.K_W = K_W;
constants.R_TC = R_TC;
constants.R_Q = R_Q;
constants.T_W = u3(1,1);
%% Experiment data — Real PDE data
% Define the size of the original matrix
[rows, cols] = size(u1);
% Generate the grid for the original matrix
[X, Y] = meshgrid(1:cols, 1:rows);
% Generate the grid for the interpolated matrix
[XI, YI] = meshgrid(linspace(1, cols, batchSize), linspace(1, rows, batchSize));
% Interpolate the matrix along each dimension
UTest1 = (interp2(X, Y, u1, XI, YI));
UTest2 = (interp2(X, Y, u2, XI, YI));
UTest3 = (interp2(X, Y, u3, XI, YI));
% Select random points
[rows, columns] = size(UTest1);
X = ceil(rand(batchSize,1)*columns);
Y = ceil(rand(batchSize,1)*rows);
for k = 1 : length(X)
row = Y(k);
col = X(k);
UTest.u1(k) = UTest1(row, col);
UTest.u2(k) = UTest2(row, col);
UTest.u3(k) = UTest3(row, col);
end
% Transfor to dlarray
x = dlarray((X./batchSize)’, "CB");
t = dlarray((Y.*t(end)./batchSize)’, "CB");
X = [t;x];
% Experiment data
UTest.u1 = dlarray(UTest.u1, "CB");
UTest.u2 = dlarray(UTest.u2, "CB");
UTest.u3 = dlarray(UTest.u3, "CB");
%% Solve inverse PINN
% Training loop
avgG = [];
avgSqG = [];
maxIters = 10000000;
lossFcn = dlaccelerate(@modelLoss);
for iter = 1:maxIters
[loss,gradients] = dlfeval(lossFcn,X,parameters,constants,UTest);
[parameters,avgG,avgSqG] = adamupdate(parameters,gradients,avgG,avgSqG,iter);
if mod(iter, 1000) == 0
fprintf("Iteration : %d, Loss : %.4f n",iter, extractdata(loss));
fprintf("Iteration: %d, Predicted Pe: %.3f, Actual Pe: %.3f, Predicted NTU: %.3f, Actual NTU: %.3fn", …
iter, extractdata(parameters.Pe), Pe, extractdata(parameters.NTU), NTU);
fprintf("Iteration: %d, Predicted NTU_W: %.3f, Actual NTU_W: %.3f, Predicted NTU_EXT: %.3f, Actual NTU_EXT: %.3fn", …
iter, extractdata(parameters.NTU_W), NTU_W, extractdata(parameters.NTU_EXT), NTU_Q);
end
end
%% PINN definition
function [loss,gradients] = modelLoss(X,parameters,constants,UTest)
% X = (t,x).
% PDE
u = predict(parameters.net, X);
u1 = u(1,:);
u2 = u(2,:);
u3 = u(3,:);
% First partial derivatives
du1 = dlgradient(sum(u1,2), X, RetainData=true, EnableHigherDerivatives=true);
du2 = dlgradient(sum(u2,2), X, RetainData=true, EnableHigherDerivatives=true);
du3 = dlgradient(sum(u3,2), X, RetainData=true, EnableHigherDerivatives=true);
du1dt = du1(1,:);
du1dx = du1(2,:);
du2dt = du2(1,:);
du2dx = du2(2,:);
du3dt = du3(1,:);
du3dx = du3(2,:);
% Second partial derivatives
d2u1 = dlgradient(sum(du1dx,2),X,RetainData=true);
d2u2 = dlgradient(sum(du2dx,2),X,RetainData=true);
d2u3 = dlgradient(sum(du3dx,2),X,RetainData=true);
d2u1dx2 = d2u1(2,:);
d2u2dx2 = d2u2(2,:);
d2u3dx2 = d2u3(2,:);
% PDE residual
odeResidual = (constants.B*du1dt + du1dx – 1/parameters.Pe*d2u1dx2 – parameters.NTU*(u2 – u1) – parameters.NTU_W*(u3 – u1)).^2;
odeResidual = odeResidual + (du2dt – constants.K_R*d2u2dx2 + parameters.NTU*(u2 – u1)).^2;
odeResidual = odeResidual + (du3dt – constants.K_W*d2u3dx2 + constants.R_TC*parameters.NTU_W*(u3 – u1) + constants.R_Q*parameters.NTU_EXT*(u3 – constants.T_W)).^2;
% Compute the mean square error of the ODE residual
pdeLoss = mean(odeResidual,"all");
% Compute the L2 difference between the predicted xpred and the true x.
reconstructionLoss = l2loss(u1,UTest.u1) + l2loss(u2,UTest.u2) + l2loss(u3,UTest.u3);
loss = pdeLoss + reconstructionLoss;
[gradients.net, gradients.Pe, gradients.NTU, gradients.NTU_W, gradients.NTU_EXT] = dlgradient(pdeLoss,parameters.net.Learnables,parameters.Pe, parameters.NTU, parameters.NTU_W, parameters.NTU_EXT);
endHello,
I have a system of PDEs simulating a heat transfer system, and I have experimental data of the behaviour of the system. I am trying to use a PINN for the identification of 4 unkwnon parameters.
I am trying first to validate the model with known parameters, but I am unable to reach any reasonable parameter value. The learning rate is too slow, any recommendations?
Thanks for the help!
To run the code you will need to download the following .mat: https://cyclomed-my.sharepoint.com/:u:/g/personal/administracion_cyclomed_onmicrosoft_com/ETlg6E6520JDnBoIOv35Bq0B0o6ZCXvAvvqG3Gn1Ht3ssA?e=hKclKH
For context this is a simplified version of the PDE:
% Identify parameters of single blow equation
% 1) Fluid (u1) –> B*du1/dt + du1/dx = 1/Pe*d2u1/dx^2 + NTU*(u2 – u1) + NTU_W(u3 – u1)
% 2) Regenerator (u2) –>du2/dx = K_R*d2u2/dx^2 – NTU*(u2 – u1)
% 3) Wall (u3) –> du3/dx = R_TC*K_W*d2u3/dx^2 – R_TC*NTU_W*(u3 – u1) – NTU_W(u3 – u3_init)
% Load Experiment data
load("Test 11.mat");
%% Neural Network Definition
batchSize = 500;
dimension = 2; % X = (t,x)
% Set up neural net.
hiddenSize = 100;
net = [
featureInputLayer(dimension)
fullyConnectedLayer(hiddenSize)
tanhLayer
fullyConnectedLayer(hiddenSize)
tanhLayer
fullyConnectedLayer(hiddenSize)
tanhLayer
fullyConnectedLayer(3)];
% Create struct of parameters
parameters.net = dlnetwork(net);
% Unknown PDE parameters
parameters.Pe = dlarray(1000);
parameters.NTU = dlarray(200);
parameters.NTU_W = dlarray(1);
parameters.NTU_EXT = dlarray(50);
% Known PDE parameters
constants.B = B;
constants.K_R = K_R;
constants.K_W = K_W;
constants.R_TC = R_TC;
constants.R_Q = R_Q;
constants.T_W = u3(1,1);
%% Experiment data — Real PDE data
% Define the size of the original matrix
[rows, cols] = size(u1);
% Generate the grid for the original matrix
[X, Y] = meshgrid(1:cols, 1:rows);
% Generate the grid for the interpolated matrix
[XI, YI] = meshgrid(linspace(1, cols, batchSize), linspace(1, rows, batchSize));
% Interpolate the matrix along each dimension
UTest1 = (interp2(X, Y, u1, XI, YI));
UTest2 = (interp2(X, Y, u2, XI, YI));
UTest3 = (interp2(X, Y, u3, XI, YI));
% Select random points
[rows, columns] = size(UTest1);
X = ceil(rand(batchSize,1)*columns);
Y = ceil(rand(batchSize,1)*rows);
for k = 1 : length(X)
row = Y(k);
col = X(k);
UTest.u1(k) = UTest1(row, col);
UTest.u2(k) = UTest2(row, col);
UTest.u3(k) = UTest3(row, col);
end
% Transfor to dlarray
x = dlarray((X./batchSize)’, "CB");
t = dlarray((Y.*t(end)./batchSize)’, "CB");
X = [t;x];
% Experiment data
UTest.u1 = dlarray(UTest.u1, "CB");
UTest.u2 = dlarray(UTest.u2, "CB");
UTest.u3 = dlarray(UTest.u3, "CB");
%% Solve inverse PINN
% Training loop
avgG = [];
avgSqG = [];
maxIters = 10000000;
lossFcn = dlaccelerate(@modelLoss);
for iter = 1:maxIters
[loss,gradients] = dlfeval(lossFcn,X,parameters,constants,UTest);
[parameters,avgG,avgSqG] = adamupdate(parameters,gradients,avgG,avgSqG,iter);
if mod(iter, 1000) == 0
fprintf("Iteration : %d, Loss : %.4f n",iter, extractdata(loss));
fprintf("Iteration: %d, Predicted Pe: %.3f, Actual Pe: %.3f, Predicted NTU: %.3f, Actual NTU: %.3fn", …
iter, extractdata(parameters.Pe), Pe, extractdata(parameters.NTU), NTU);
fprintf("Iteration: %d, Predicted NTU_W: %.3f, Actual NTU_W: %.3f, Predicted NTU_EXT: %.3f, Actual NTU_EXT: %.3fn", …
iter, extractdata(parameters.NTU_W), NTU_W, extractdata(parameters.NTU_EXT), NTU_Q);
end
end
%% PINN definition
function [loss,gradients] = modelLoss(X,parameters,constants,UTest)
% X = (t,x).
% PDE
u = predict(parameters.net, X);
u1 = u(1,:);
u2 = u(2,:);
u3 = u(3,:);
% First partial derivatives
du1 = dlgradient(sum(u1,2), X, RetainData=true, EnableHigherDerivatives=true);
du2 = dlgradient(sum(u2,2), X, RetainData=true, EnableHigherDerivatives=true);
du3 = dlgradient(sum(u3,2), X, RetainData=true, EnableHigherDerivatives=true);
du1dt = du1(1,:);
du1dx = du1(2,:);
du2dt = du2(1,:);
du2dx = du2(2,:);
du3dt = du3(1,:);
du3dx = du3(2,:);
% Second partial derivatives
d2u1 = dlgradient(sum(du1dx,2),X,RetainData=true);
d2u2 = dlgradient(sum(du2dx,2),X,RetainData=true);
d2u3 = dlgradient(sum(du3dx,2),X,RetainData=true);
d2u1dx2 = d2u1(2,:);
d2u2dx2 = d2u2(2,:);
d2u3dx2 = d2u3(2,:);
% PDE residual
odeResidual = (constants.B*du1dt + du1dx – 1/parameters.Pe*d2u1dx2 – parameters.NTU*(u2 – u1) – parameters.NTU_W*(u3 – u1)).^2;
odeResidual = odeResidual + (du2dt – constants.K_R*d2u2dx2 + parameters.NTU*(u2 – u1)).^2;
odeResidual = odeResidual + (du3dt – constants.K_W*d2u3dx2 + constants.R_TC*parameters.NTU_W*(u3 – u1) + constants.R_Q*parameters.NTU_EXT*(u3 – constants.T_W)).^2;
% Compute the mean square error of the ODE residual
pdeLoss = mean(odeResidual,"all");
% Compute the L2 difference between the predicted xpred and the true x.
reconstructionLoss = l2loss(u1,UTest.u1) + l2loss(u2,UTest.u2) + l2loss(u3,UTest.u3);
loss = pdeLoss + reconstructionLoss;
[gradients.net, gradients.Pe, gradients.NTU, gradients.NTU_W, gradients.NTU_EXT] = dlgradient(pdeLoss,parameters.net.Learnables,parameters.Pe, parameters.NTU, parameters.NTU_W, parameters.NTU_EXT);
end Hello,
I have a system of PDEs simulating a heat transfer system, and I have experimental data of the behaviour of the system. I am trying to use a PINN for the identification of 4 unkwnon parameters.
I am trying first to validate the model with known parameters, but I am unable to reach any reasonable parameter value. The learning rate is too slow, any recommendations?
Thanks for the help!
To run the code you will need to download the following .mat: https://cyclomed-my.sharepoint.com/:u:/g/personal/administracion_cyclomed_onmicrosoft_com/ETlg6E6520JDnBoIOv35Bq0B0o6ZCXvAvvqG3Gn1Ht3ssA?e=hKclKH
For context this is a simplified version of the PDE:
% Identify parameters of single blow equation
% 1) Fluid (u1) –> B*du1/dt + du1/dx = 1/Pe*d2u1/dx^2 + NTU*(u2 – u1) + NTU_W(u3 – u1)
% 2) Regenerator (u2) –>du2/dx = K_R*d2u2/dx^2 – NTU*(u2 – u1)
% 3) Wall (u3) –> du3/dx = R_TC*K_W*d2u3/dx^2 – R_TC*NTU_W*(u3 – u1) – NTU_W(u3 – u3_init)
% Load Experiment data
load("Test 11.mat");
%% Neural Network Definition
batchSize = 500;
dimension = 2; % X = (t,x)
% Set up neural net.
hiddenSize = 100;
net = [
featureInputLayer(dimension)
fullyConnectedLayer(hiddenSize)
tanhLayer
fullyConnectedLayer(hiddenSize)
tanhLayer
fullyConnectedLayer(hiddenSize)
tanhLayer
fullyConnectedLayer(3)];
% Create struct of parameters
parameters.net = dlnetwork(net);
% Unknown PDE parameters
parameters.Pe = dlarray(1000);
parameters.NTU = dlarray(200);
parameters.NTU_W = dlarray(1);
parameters.NTU_EXT = dlarray(50);
% Known PDE parameters
constants.B = B;
constants.K_R = K_R;
constants.K_W = K_W;
constants.R_TC = R_TC;
constants.R_Q = R_Q;
constants.T_W = u3(1,1);
%% Experiment data — Real PDE data
% Define the size of the original matrix
[rows, cols] = size(u1);
% Generate the grid for the original matrix
[X, Y] = meshgrid(1:cols, 1:rows);
% Generate the grid for the interpolated matrix
[XI, YI] = meshgrid(linspace(1, cols, batchSize), linspace(1, rows, batchSize));
% Interpolate the matrix along each dimension
UTest1 = (interp2(X, Y, u1, XI, YI));
UTest2 = (interp2(X, Y, u2, XI, YI));
UTest3 = (interp2(X, Y, u3, XI, YI));
% Select random points
[rows, columns] = size(UTest1);
X = ceil(rand(batchSize,1)*columns);
Y = ceil(rand(batchSize,1)*rows);
for k = 1 : length(X)
row = Y(k);
col = X(k);
UTest.u1(k) = UTest1(row, col);
UTest.u2(k) = UTest2(row, col);
UTest.u3(k) = UTest3(row, col);
end
% Transfor to dlarray
x = dlarray((X./batchSize)’, "CB");
t = dlarray((Y.*t(end)./batchSize)’, "CB");
X = [t;x];
% Experiment data
UTest.u1 = dlarray(UTest.u1, "CB");
UTest.u2 = dlarray(UTest.u2, "CB");
UTest.u3 = dlarray(UTest.u3, "CB");
%% Solve inverse PINN
% Training loop
avgG = [];
avgSqG = [];
maxIters = 10000000;
lossFcn = dlaccelerate(@modelLoss);
for iter = 1:maxIters
[loss,gradients] = dlfeval(lossFcn,X,parameters,constants,UTest);
[parameters,avgG,avgSqG] = adamupdate(parameters,gradients,avgG,avgSqG,iter);
if mod(iter, 1000) == 0
fprintf("Iteration : %d, Loss : %.4f n",iter, extractdata(loss));
fprintf("Iteration: %d, Predicted Pe: %.3f, Actual Pe: %.3f, Predicted NTU: %.3f, Actual NTU: %.3fn", …
iter, extractdata(parameters.Pe), Pe, extractdata(parameters.NTU), NTU);
fprintf("Iteration: %d, Predicted NTU_W: %.3f, Actual NTU_W: %.3f, Predicted NTU_EXT: %.3f, Actual NTU_EXT: %.3fn", …
iter, extractdata(parameters.NTU_W), NTU_W, extractdata(parameters.NTU_EXT), NTU_Q);
end
end
%% PINN definition
function [loss,gradients] = modelLoss(X,parameters,constants,UTest)
% X = (t,x).
% PDE
u = predict(parameters.net, X);
u1 = u(1,:);
u2 = u(2,:);
u3 = u(3,:);
% First partial derivatives
du1 = dlgradient(sum(u1,2), X, RetainData=true, EnableHigherDerivatives=true);
du2 = dlgradient(sum(u2,2), X, RetainData=true, EnableHigherDerivatives=true);
du3 = dlgradient(sum(u3,2), X, RetainData=true, EnableHigherDerivatives=true);
du1dt = du1(1,:);
du1dx = du1(2,:);
du2dt = du2(1,:);
du2dx = du2(2,:);
du3dt = du3(1,:);
du3dx = du3(2,:);
% Second partial derivatives
d2u1 = dlgradient(sum(du1dx,2),X,RetainData=true);
d2u2 = dlgradient(sum(du2dx,2),X,RetainData=true);
d2u3 = dlgradient(sum(du3dx,2),X,RetainData=true);
d2u1dx2 = d2u1(2,:);
d2u2dx2 = d2u2(2,:);
d2u3dx2 = d2u3(2,:);
% PDE residual
odeResidual = (constants.B*du1dt + du1dx – 1/parameters.Pe*d2u1dx2 – parameters.NTU*(u2 – u1) – parameters.NTU_W*(u3 – u1)).^2;
odeResidual = odeResidual + (du2dt – constants.K_R*d2u2dx2 + parameters.NTU*(u2 – u1)).^2;
odeResidual = odeResidual + (du3dt – constants.K_W*d2u3dx2 + constants.R_TC*parameters.NTU_W*(u3 – u1) + constants.R_Q*parameters.NTU_EXT*(u3 – constants.T_W)).^2;
% Compute the mean square error of the ODE residual
pdeLoss = mean(odeResidual,"all");
% Compute the L2 difference between the predicted xpred and the true x.
reconstructionLoss = l2loss(u1,UTest.u1) + l2loss(u2,UTest.u2) + l2loss(u3,UTest.u3);
loss = pdeLoss + reconstructionLoss;
[gradients.net, gradients.Pe, gradients.NTU, gradients.NTU_W, gradients.NTU_EXT] = dlgradient(pdeLoss,parameters.net.Learnables,parameters.Pe, parameters.NTU, parameters.NTU_W, parameters.NTU_EXT);
end pde, pinn MATLAB Answers — New Questions
2 variables symbolic function representation
Hello everyone!
I need to represent a two variables function.
From the following determinant
A =
I obtained the quadratic equation:
a =
These are the vectors p and q:
p00 = 0.909722222222223
p10 = -0.233216488601376
p01= 0.264523899711384
p20=-1.06968750000000
p11=-0.0207056503962889
p02=0.578645833333333
q00=0.907638888888890
q10=0.00799330706899891
q01=0.0257069830283098
q20=0.0382031250000013
q11=0.0414113007925775
q02=-0.628619791666669
I want to impose the function a ==0 and in order to obtain the curve and then I would like to represent it in a graph.
Is there a way to do it?
I used ht = matlabFunction(a) to obtain
ht = function_handle with value:
@(p01,p02,p10,p11,p20,q01,q10,q11,q20,x,y)(p20.*q11.*2.0-p11.*q20.*2.0).*x.^2+(p20.*q20.*4.0-p02.*q20.*4.0).*x.*y+(p10.*q11-p01.*q20.*2.0-p11.*q10+p20.*q01.*2.0).*x+(p11.*q20.*2.0-p02.*q11.*2.0).*y.^2+(p11.*q01-p02.*q10.*2.0-p01.*q11+p10.*q20.*2.0).*y+(p10.*q01-p01.*q10)
I don’t understand if it is useful.
Thank you very much!
LauraHello everyone!
I need to represent a two variables function.
From the following determinant
A =
I obtained the quadratic equation:
a =
These are the vectors p and q:
p00 = 0.909722222222223
p10 = -0.233216488601376
p01= 0.264523899711384
p20=-1.06968750000000
p11=-0.0207056503962889
p02=0.578645833333333
q00=0.907638888888890
q10=0.00799330706899891
q01=0.0257069830283098
q20=0.0382031250000013
q11=0.0414113007925775
q02=-0.628619791666669
I want to impose the function a ==0 and in order to obtain the curve and then I would like to represent it in a graph.
Is there a way to do it?
I used ht = matlabFunction(a) to obtain
ht = function_handle with value:
@(p01,p02,p10,p11,p20,q01,q10,q11,q20,x,y)(p20.*q11.*2.0-p11.*q20.*2.0).*x.^2+(p20.*q20.*4.0-p02.*q20.*4.0).*x.*y+(p10.*q11-p01.*q20.*2.0-p11.*q10+p20.*q01.*2.0).*x+(p11.*q20.*2.0-p02.*q11.*2.0).*y.^2+(p11.*q01-p02.*q10.*2.0-p01.*q11+p10.*q20.*2.0).*y+(p10.*q01-p01.*q10)
I don’t understand if it is useful.
Thank you very much!
Laura Hello everyone!
I need to represent a two variables function.
From the following determinant
A =
I obtained the quadratic equation:
a =
These are the vectors p and q:
p00 = 0.909722222222223
p10 = -0.233216488601376
p01= 0.264523899711384
p20=-1.06968750000000
p11=-0.0207056503962889
p02=0.578645833333333
q00=0.907638888888890
q10=0.00799330706899891
q01=0.0257069830283098
q20=0.0382031250000013
q11=0.0414113007925775
q02=-0.628619791666669
I want to impose the function a ==0 and in order to obtain the curve and then I would like to represent it in a graph.
Is there a way to do it?
I used ht = matlabFunction(a) to obtain
ht = function_handle with value:
@(p01,p02,p10,p11,p20,q01,q10,q11,q20,x,y)(p20.*q11.*2.0-p11.*q20.*2.0).*x.^2+(p20.*q20.*4.0-p02.*q20.*4.0).*x.*y+(p10.*q11-p01.*q20.*2.0-p11.*q10+p20.*q01.*2.0).*x+(p11.*q20.*2.0-p02.*q11.*2.0).*y.^2+(p11.*q01-p02.*q10.*2.0-p01.*q11+p10.*q20.*2.0).*y+(p10.*q01-p01.*q10)
I don’t understand if it is useful.
Thank you very much!
Laura curve fitting, symbolic MATLAB Answers — New Questions
I can’t detect USRP X310 with UBX-160 Daughter board in MATLAB.
I am trying to connect USRP X310 with daughter board of UBX-160 with MATLAB 2024a. I tried Wireless Testbench™ Support Package for NI USRP Radios to detect my radio but it gives me error.
By using the findsdru command I see the following output.
I am not sure what to do? Anyone can help?I am trying to connect USRP X310 with daughter board of UBX-160 with MATLAB 2024a. I tried Wireless Testbench™ Support Package for NI USRP Radios to detect my radio but it gives me error.
By using the findsdru command I see the following output.
I am not sure what to do? Anyone can help? I am trying to connect USRP X310 with daughter board of UBX-160 with MATLAB 2024a. I tried Wireless Testbench™ Support Package for NI USRP Radios to detect my radio but it gives me error.
By using the findsdru command I see the following output.
I am not sure what to do? Anyone can help? usrp, sdr, x310, radio MATLAB Answers — New Questions
Find natural equation w with 5 dof
% Using matrix to determine natural frequency w of 5 DOF
clc; % Clear command window
clear; % Clear workspace
syms w; % Define w as a symbolic variable
% Define masses, damping coefficients, and stiffness coefficients
m1 = 1.8; m2 = 6.3; m3 = 5.4; m4 = 22.5; m5 = 54;
c2 = 10000; c3 = 500; c4 = 1500; c5 = 1100;
k2 = 1*10^8; k3 = 50*10^3; k4 = 75*10^3; k5 = 10*10^3;% Using matrix to determine natural frequency w of 5 DOF
clc; % Clear command window
clear; % Clear workspace
syms w; % Define w as a symbolic variable
% Define masses, damping coefficients, and stiffness coefficients
m1 = 1.8; m2 = 6.3; m3 = 5.4; m4 = 22.5; m5 = 54;
c2 = 10000; c3 = 500; c4 = 1500; c5 = 1100;
k2 = 1*10^8; k3 = 50*10^3; k4 = 75*10^3; k5 = 10*10^3; % Using matrix to determine natural frequency w of 5 DOF
clc; % Clear command window
clear; % Clear workspace
syms w; % Define w as a symbolic variable
% Define masses, damping coefficients, and stiffness coefficients
m1 = 1.8; m2 = 6.3; m3 = 5.4; m4 = 22.5; m5 = 54;
c2 = 10000; c3 = 500; c4 = 1500; c5 = 1100;
k2 = 1*10^8; k3 = 50*10^3; k4 = 75*10^3; k5 = 10*10^3; matlab, vibration, natural frequency MATLAB Answers — New Questions
Unrecognized function or variable ” ” , when I use my function
Hi,
I write some function that will make a fit for my data. this is my function:
function Xmax = fit_function(x,y)
X1 = x(x>0.5 & x<2);
Y1 = y(x>0.5 & x<2);
% ymax calculated analytically with Wolfram Mathematica
ymax = @(b) (2-b(2)/b(1))*(2*b(1)/b(2)-1)^(-b(2)/2/b(1));
modelfun = @(b,x) b(3)/ymax(b)*exp((x-b(4))*(b(1)-b(2))).*sech(b(1)*(x-b(4)));
bguess=[78, 10, peaks(1),x(t_peaks(1))];
% [alpha, beta, amplitude, x offset]
% 78 and 10 were calculated by cftool (after given there a guess of 80,20)
beta = nlinfit(X1, Y1, modelfun, bguess);
fittedCurve = modelfun(beta, X1);
Xmax=log(-1+(2*beta(1)/beta(2)));
when I apply this function on some data, I have a problem in the line of bguess.
The function is able to read the "peaks(1)" variable, but not the t_peaks(1) variable. both of them save in the workspace, and slao both of them is double file.
as I say in the summary, the error is:
>> Xmax=fit_function(x,y);
Unrecognized function or variable ‘t_peaks’.
Error in fit_function (line 12)
bguess=[78, 10, peaks(1), x(t_peaks(1))];
why is append?
It’s strange that it can read one of the variables and not the other..
Thanks!(:Hi,
I write some function that will make a fit for my data. this is my function:
function Xmax = fit_function(x,y)
X1 = x(x>0.5 & x<2);
Y1 = y(x>0.5 & x<2);
% ymax calculated analytically with Wolfram Mathematica
ymax = @(b) (2-b(2)/b(1))*(2*b(1)/b(2)-1)^(-b(2)/2/b(1));
modelfun = @(b,x) b(3)/ymax(b)*exp((x-b(4))*(b(1)-b(2))).*sech(b(1)*(x-b(4)));
bguess=[78, 10, peaks(1),x(t_peaks(1))];
% [alpha, beta, amplitude, x offset]
% 78 and 10 were calculated by cftool (after given there a guess of 80,20)
beta = nlinfit(X1, Y1, modelfun, bguess);
fittedCurve = modelfun(beta, X1);
Xmax=log(-1+(2*beta(1)/beta(2)));
when I apply this function on some data, I have a problem in the line of bguess.
The function is able to read the "peaks(1)" variable, but not the t_peaks(1) variable. both of them save in the workspace, and slao both of them is double file.
as I say in the summary, the error is:
>> Xmax=fit_function(x,y);
Unrecognized function or variable ‘t_peaks’.
Error in fit_function (line 12)
bguess=[78, 10, peaks(1), x(t_peaks(1))];
why is append?
It’s strange that it can read one of the variables and not the other..
Thanks!(: Hi,
I write some function that will make a fit for my data. this is my function:
function Xmax = fit_function(x,y)
X1 = x(x>0.5 & x<2);
Y1 = y(x>0.5 & x<2);
% ymax calculated analytically with Wolfram Mathematica
ymax = @(b) (2-b(2)/b(1))*(2*b(1)/b(2)-1)^(-b(2)/2/b(1));
modelfun = @(b,x) b(3)/ymax(b)*exp((x-b(4))*(b(1)-b(2))).*sech(b(1)*(x-b(4)));
bguess=[78, 10, peaks(1),x(t_peaks(1))];
% [alpha, beta, amplitude, x offset]
% 78 and 10 were calculated by cftool (after given there a guess of 80,20)
beta = nlinfit(X1, Y1, modelfun, bguess);
fittedCurve = modelfun(beta, X1);
Xmax=log(-1+(2*beta(1)/beta(2)));
when I apply this function on some data, I have a problem in the line of bguess.
The function is able to read the "peaks(1)" variable, but not the t_peaks(1) variable. both of them save in the workspace, and slao both of them is double file.
as I say in the summary, the error is:
>> Xmax=fit_function(x,y);
Unrecognized function or variable ‘t_peaks’.
Error in fit_function (line 12)
bguess=[78, 10, peaks(1), x(t_peaks(1))];
why is append?
It’s strange that it can read one of the variables and not the other..
Thanks!(: function, variable MATLAB Answers — New Questions