Tag Archives: matlab
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
Non-linearity errors and zero-crossing errors while training a RL Agent
A few days ago I posted a question about the training of an agent applied to the control of a nonlinear model of a three-degree-of-freedom aircraft. During training, randomly, I get this warning
The output port signal type of ‘RL_Training_TECS_Model/Environment System/State Propagator/Forces, Moments, 3DoF/Aerodynamic Coefficients, 3DoF/Datcom Aerodynamic Model’ is real (non-complex), however, the evaluated output is complex. Consider setting the ‘OutputSignalType’ to complex
followed by this error
Error using rl.internal.train.OffPolicyTrainer/run_internal_/nestedRunEpisode (line 284)
An error occurred while running the simulation for model ‘RL_Training_TECS_Model’ with the following RL agent blocks:
RL_Training_TECS_Model/RL TECS Alt Hold
Error in rl.internal.train.OffPolicyTrainer/run_internal_ (line 351)
out = nestedRunEpisode(policy);
Error in rl.internal.train.OffPolicyTrainer/run_ (line 40)
result = run_internal_(this);
Error in rl.internal.train.Trainer/run (line 8)
result = run_(this);
Error in rl.internal.trainmgr.OnlineTrainingManager/run_ (line 112)
trainResult = run(trainer);
Error in rl.internal.trainmgr.TrainingManager/run (line 4)
result = run_(this);
Error in rl.agent.AbstractAgent/train (line 86)
trainingResult = run(tm);
Caused by:
Error using rl.env.internal.reportSimulinkSimError (line 29)
Simulink will stop the simulation of model ‘RL_Training_TECS_Model’ because the 1 zero crossing signal(s) identified below caused 1000 consecutive zero crossing events in time interval between 7.6446467665241798e-11 and 7.6446467670045701e-11.
————————————————– ——————————
Number of consecutive zero-crossings: 1000
Zero-crossing signal name : SwitchCond
Block type: Switch
Block path : ‘RL_Training_TECS_Model/Environment System/State Propagator/Forces, Moments, 3DoF/Aerodynamic Coefficients, 3DoF/Switch’
————————————————– ——————————
or this one
Error using rl.internal.train.OffPolicyTrainer/run_internal_/nestedRunEpisode (line 284)
An error occurred while running the simulation for model ‘RL_Training_TECS_Model’ with the following RL agent blocks:
RL_Training_TECS_Model/RL TECS Alt Hold
Error in rl.internal.train.OffPolicyTrainer/run_internal_ (line 351)
out = nestedRunEpisode(policy);
Error in rl.internal.train.OffPolicyTrainer/run_ (line 40)
result = run_internal_(this);
Error in rl.internal.train.Trainer/run (line 8)
result = run_(this);
Error in rl.internal.trainmgr.OnlineTrainingManager/run_ (line 112)
trainResult = run(trainer);
Error in rl.internal.trainmgr.TrainingManager/run (line 4)
result = run_(this);
Error in rl.agent.AbstractAgent/train (line 86)
trainingResult = run(tm);
Caused by:
Error using rl.env.internal.reportSimulinkSimError (line 29)
Solver encountered an error while simulating model ‘RL_Training_TECS_Model’ at time 1.140683144978552e-08 and cannot continue. Please check the model for errors.
Error using rl.env.internal.reportSimulinkSimError (line 29)
Nonlinear iteration is not converging with step size reduced to hmin (4.05252E-23) at time 1.14068E-08. Try reducing the minimum step size and/or relax the relative error tolerance.
At the start of each episode, the reset function trims the aircraft to a safe area I specify and then linearizes. What could these errors be due to?A few days ago I posted a question about the training of an agent applied to the control of a nonlinear model of a three-degree-of-freedom aircraft. During training, randomly, I get this warning
The output port signal type of ‘RL_Training_TECS_Model/Environment System/State Propagator/Forces, Moments, 3DoF/Aerodynamic Coefficients, 3DoF/Datcom Aerodynamic Model’ is real (non-complex), however, the evaluated output is complex. Consider setting the ‘OutputSignalType’ to complex
followed by this error
Error using rl.internal.train.OffPolicyTrainer/run_internal_/nestedRunEpisode (line 284)
An error occurred while running the simulation for model ‘RL_Training_TECS_Model’ with the following RL agent blocks:
RL_Training_TECS_Model/RL TECS Alt Hold
Error in rl.internal.train.OffPolicyTrainer/run_internal_ (line 351)
out = nestedRunEpisode(policy);
Error in rl.internal.train.OffPolicyTrainer/run_ (line 40)
result = run_internal_(this);
Error in rl.internal.train.Trainer/run (line 8)
result = run_(this);
Error in rl.internal.trainmgr.OnlineTrainingManager/run_ (line 112)
trainResult = run(trainer);
Error in rl.internal.trainmgr.TrainingManager/run (line 4)
result = run_(this);
Error in rl.agent.AbstractAgent/train (line 86)
trainingResult = run(tm);
Caused by:
Error using rl.env.internal.reportSimulinkSimError (line 29)
Simulink will stop the simulation of model ‘RL_Training_TECS_Model’ because the 1 zero crossing signal(s) identified below caused 1000 consecutive zero crossing events in time interval between 7.6446467665241798e-11 and 7.6446467670045701e-11.
————————————————– ——————————
Number of consecutive zero-crossings: 1000
Zero-crossing signal name : SwitchCond
Block type: Switch
Block path : ‘RL_Training_TECS_Model/Environment System/State Propagator/Forces, Moments, 3DoF/Aerodynamic Coefficients, 3DoF/Switch’
————————————————– ——————————
or this one
Error using rl.internal.train.OffPolicyTrainer/run_internal_/nestedRunEpisode (line 284)
An error occurred while running the simulation for model ‘RL_Training_TECS_Model’ with the following RL agent blocks:
RL_Training_TECS_Model/RL TECS Alt Hold
Error in rl.internal.train.OffPolicyTrainer/run_internal_ (line 351)
out = nestedRunEpisode(policy);
Error in rl.internal.train.OffPolicyTrainer/run_ (line 40)
result = run_internal_(this);
Error in rl.internal.train.Trainer/run (line 8)
result = run_(this);
Error in rl.internal.trainmgr.OnlineTrainingManager/run_ (line 112)
trainResult = run(trainer);
Error in rl.internal.trainmgr.TrainingManager/run (line 4)
result = run_(this);
Error in rl.agent.AbstractAgent/train (line 86)
trainingResult = run(tm);
Caused by:
Error using rl.env.internal.reportSimulinkSimError (line 29)
Solver encountered an error while simulating model ‘RL_Training_TECS_Model’ at time 1.140683144978552e-08 and cannot continue. Please check the model for errors.
Error using rl.env.internal.reportSimulinkSimError (line 29)
Nonlinear iteration is not converging with step size reduced to hmin (4.05252E-23) at time 1.14068E-08. Try reducing the minimum step size and/or relax the relative error tolerance.
At the start of each episode, the reset function trims the aircraft to a safe area I specify and then linearizes. What could these errors be due to? A few days ago I posted a question about the training of an agent applied to the control of a nonlinear model of a three-degree-of-freedom aircraft. During training, randomly, I get this warning
The output port signal type of ‘RL_Training_TECS_Model/Environment System/State Propagator/Forces, Moments, 3DoF/Aerodynamic Coefficients, 3DoF/Datcom Aerodynamic Model’ is real (non-complex), however, the evaluated output is complex. Consider setting the ‘OutputSignalType’ to complex
followed by this error
Error using rl.internal.train.OffPolicyTrainer/run_internal_/nestedRunEpisode (line 284)
An error occurred while running the simulation for model ‘RL_Training_TECS_Model’ with the following RL agent blocks:
RL_Training_TECS_Model/RL TECS Alt Hold
Error in rl.internal.train.OffPolicyTrainer/run_internal_ (line 351)
out = nestedRunEpisode(policy);
Error in rl.internal.train.OffPolicyTrainer/run_ (line 40)
result = run_internal_(this);
Error in rl.internal.train.Trainer/run (line 8)
result = run_(this);
Error in rl.internal.trainmgr.OnlineTrainingManager/run_ (line 112)
trainResult = run(trainer);
Error in rl.internal.trainmgr.TrainingManager/run (line 4)
result = run_(this);
Error in rl.agent.AbstractAgent/train (line 86)
trainingResult = run(tm);
Caused by:
Error using rl.env.internal.reportSimulinkSimError (line 29)
Simulink will stop the simulation of model ‘RL_Training_TECS_Model’ because the 1 zero crossing signal(s) identified below caused 1000 consecutive zero crossing events in time interval between 7.6446467665241798e-11 and 7.6446467670045701e-11.
————————————————– ——————————
Number of consecutive zero-crossings: 1000
Zero-crossing signal name : SwitchCond
Block type: Switch
Block path : ‘RL_Training_TECS_Model/Environment System/State Propagator/Forces, Moments, 3DoF/Aerodynamic Coefficients, 3DoF/Switch’
————————————————– ——————————
or this one
Error using rl.internal.train.OffPolicyTrainer/run_internal_/nestedRunEpisode (line 284)
An error occurred while running the simulation for model ‘RL_Training_TECS_Model’ with the following RL agent blocks:
RL_Training_TECS_Model/RL TECS Alt Hold
Error in rl.internal.train.OffPolicyTrainer/run_internal_ (line 351)
out = nestedRunEpisode(policy);
Error in rl.internal.train.OffPolicyTrainer/run_ (line 40)
result = run_internal_(this);
Error in rl.internal.train.Trainer/run (line 8)
result = run_(this);
Error in rl.internal.trainmgr.OnlineTrainingManager/run_ (line 112)
trainResult = run(trainer);
Error in rl.internal.trainmgr.TrainingManager/run (line 4)
result = run_(this);
Error in rl.agent.AbstractAgent/train (line 86)
trainingResult = run(tm);
Caused by:
Error using rl.env.internal.reportSimulinkSimError (line 29)
Solver encountered an error while simulating model ‘RL_Training_TECS_Model’ at time 1.140683144978552e-08 and cannot continue. Please check the model for errors.
Error using rl.env.internal.reportSimulinkSimError (line 29)
Nonlinear iteration is not converging with step size reduced to hmin (4.05252E-23) at time 1.14068E-08. Try reducing the minimum step size and/or relax the relative error tolerance.
At the start of each episode, the reset function trims the aircraft to a safe area I specify and then linearizes. What could these errors be due to? matlab, simulink, error, reinforcement_learning, nonlinear, zero-crossing MATLAB Answers — New Questions
Best way to organize categorical data for plotting
I have wind speed data that I want to split and plot in several different ways. For instance, I may want to plot a 3d bar plot with different combinations of wind speed, month, frequency count, altitude. Or a subsection of the data as stacked bar plot or area plot. I’ve been looking at different ways of organizing the data to make plotting different variables and subsections easy, but I’m not used to working with categorical data in matlab, and I keep running into limitations with table/timetable. I’m coming from Python (and older versions of Matlab) and I find Matlab 2019 to be close enough to be just a bit frustrating.
I’m looking for advice on what might be the best way to organize data like this to make plotting quick and flexible. Clearly there’s some logic to this aspect of Matlab that I’ve missed. I’ve previously simply split the data into various matrices and manipulated them for plotting, which is plain and simple, but I’m sure there are better and more advanced ways to do this if one knows how.
I’ve attached the file GC.mat where the data is organized by month, wind speed (5 m/s bins), altitude (2 km bins) and count. I’ve also added part of the original timetable w_tt.csv with 2 s wind speed data (the original data covers 6 years).
I can provide examples of my plotting attempts and try to figure out why it’s not working, but I have a feeling the main problem is that I’ve just not understood the best way to organize the data, so I’m starting with an attempt to learn why this is/isn’t a good approach.
Example table:
166×6 table
monthname_Time disc_Altitude disc_Windspeed GroupCount norm perc
______________ _____________ ______________ __________ __________ __________
January [20000, Inf] [0, 2) 503 4.3455e-05 0.0043455
January [20000, Inf] [2, 4) 1355 0.00011706 0.011706
January [20000, Inf] [4, 6) 2452 0.00021183 0.021183
January [20000, Inf] [6, 8) 2931 0.00025321 0.025321
January [20000, Inf] [8, 10) 3516 0.00030375 0.030375
January [20000, Inf] [10, 12) 3640 0.00031447 0.031447
January [20000, Inf] [12, 14) 3392 0.00029304 0.029304
January [20000, Inf] [14, 16) 2398 0.00020717 0.020717
January [20000, Inf] [16, 18) 2134 0.00018436 0.018436
January [20000, Inf] [18, 20) 2815 0.00024319 0.024319
January [20000, Inf] [20, 22) 3811 0.00032924 0.032924
January [20000, Inf] [22, 24) 4504 0.00038911 0.038911
Example timetable data:
Time Windspeed Altitude
___________________ _________ ________
01/01/2015 00:17:01 27.3 18317
01/01/2015 00:17:03 27.3 18325
01/01/2015 00:17:05 27.2 18334
01/01/2015 00:17:07 27.1 18343
01/01/2015 00:17:09 27 18352
01/01/2015 00:17:11 26.9 18361I have wind speed data that I want to split and plot in several different ways. For instance, I may want to plot a 3d bar plot with different combinations of wind speed, month, frequency count, altitude. Or a subsection of the data as stacked bar plot or area plot. I’ve been looking at different ways of organizing the data to make plotting different variables and subsections easy, but I’m not used to working with categorical data in matlab, and I keep running into limitations with table/timetable. I’m coming from Python (and older versions of Matlab) and I find Matlab 2019 to be close enough to be just a bit frustrating.
I’m looking for advice on what might be the best way to organize data like this to make plotting quick and flexible. Clearly there’s some logic to this aspect of Matlab that I’ve missed. I’ve previously simply split the data into various matrices and manipulated them for plotting, which is plain and simple, but I’m sure there are better and more advanced ways to do this if one knows how.
I’ve attached the file GC.mat where the data is organized by month, wind speed (5 m/s bins), altitude (2 km bins) and count. I’ve also added part of the original timetable w_tt.csv with 2 s wind speed data (the original data covers 6 years).
I can provide examples of my plotting attempts and try to figure out why it’s not working, but I have a feeling the main problem is that I’ve just not understood the best way to organize the data, so I’m starting with an attempt to learn why this is/isn’t a good approach.
Example table:
166×6 table
monthname_Time disc_Altitude disc_Windspeed GroupCount norm perc
______________ _____________ ______________ __________ __________ __________
January [20000, Inf] [0, 2) 503 4.3455e-05 0.0043455
January [20000, Inf] [2, 4) 1355 0.00011706 0.011706
January [20000, Inf] [4, 6) 2452 0.00021183 0.021183
January [20000, Inf] [6, 8) 2931 0.00025321 0.025321
January [20000, Inf] [8, 10) 3516 0.00030375 0.030375
January [20000, Inf] [10, 12) 3640 0.00031447 0.031447
January [20000, Inf] [12, 14) 3392 0.00029304 0.029304
January [20000, Inf] [14, 16) 2398 0.00020717 0.020717
January [20000, Inf] [16, 18) 2134 0.00018436 0.018436
January [20000, Inf] [18, 20) 2815 0.00024319 0.024319
January [20000, Inf] [20, 22) 3811 0.00032924 0.032924
January [20000, Inf] [22, 24) 4504 0.00038911 0.038911
Example timetable data:
Time Windspeed Altitude
___________________ _________ ________
01/01/2015 00:17:01 27.3 18317
01/01/2015 00:17:03 27.3 18325
01/01/2015 00:17:05 27.2 18334
01/01/2015 00:17:07 27.1 18343
01/01/2015 00:17:09 27 18352
01/01/2015 00:17:11 26.9 18361 I have wind speed data that I want to split and plot in several different ways. For instance, I may want to plot a 3d bar plot with different combinations of wind speed, month, frequency count, altitude. Or a subsection of the data as stacked bar plot or area plot. I’ve been looking at different ways of organizing the data to make plotting different variables and subsections easy, but I’m not used to working with categorical data in matlab, and I keep running into limitations with table/timetable. I’m coming from Python (and older versions of Matlab) and I find Matlab 2019 to be close enough to be just a bit frustrating.
I’m looking for advice on what might be the best way to organize data like this to make plotting quick and flexible. Clearly there’s some logic to this aspect of Matlab that I’ve missed. I’ve previously simply split the data into various matrices and manipulated them for plotting, which is plain and simple, but I’m sure there are better and more advanced ways to do this if one knows how.
I’ve attached the file GC.mat where the data is organized by month, wind speed (5 m/s bins), altitude (2 km bins) and count. I’ve also added part of the original timetable w_tt.csv with 2 s wind speed data (the original data covers 6 years).
I can provide examples of my plotting attempts and try to figure out why it’s not working, but I have a feeling the main problem is that I’ve just not understood the best way to organize the data, so I’m starting with an attempt to learn why this is/isn’t a good approach.
Example table:
166×6 table
monthname_Time disc_Altitude disc_Windspeed GroupCount norm perc
______________ _____________ ______________ __________ __________ __________
January [20000, Inf] [0, 2) 503 4.3455e-05 0.0043455
January [20000, Inf] [2, 4) 1355 0.00011706 0.011706
January [20000, Inf] [4, 6) 2452 0.00021183 0.021183
January [20000, Inf] [6, 8) 2931 0.00025321 0.025321
January [20000, Inf] [8, 10) 3516 0.00030375 0.030375
January [20000, Inf] [10, 12) 3640 0.00031447 0.031447
January [20000, Inf] [12, 14) 3392 0.00029304 0.029304
January [20000, Inf] [14, 16) 2398 0.00020717 0.020717
January [20000, Inf] [16, 18) 2134 0.00018436 0.018436
January [20000, Inf] [18, 20) 2815 0.00024319 0.024319
January [20000, Inf] [20, 22) 3811 0.00032924 0.032924
January [20000, Inf] [22, 24) 4504 0.00038911 0.038911
Example timetable data:
Time Windspeed Altitude
___________________ _________ ________
01/01/2015 00:17:01 27.3 18317
01/01/2015 00:17:03 27.3 18325
01/01/2015 00:17:05 27.2 18334
01/01/2015 00:17:07 27.1 18343
01/01/2015 00:17:09 27 18352
01/01/2015 00:17:11 26.9 18361 categorical data, timetable, plot, histogram, bar plot MATLAB Answers — New Questions
How to troubleshoot the issue :”slot mate is not supported,” and the constraint has been exported as an ”unknown constraint” ?
I have imported an assembly from solidworks into sim mechanics so I can create a controller for the assembly. The problem is simulink doesn’t seem to recognize the "Slot Mate" from Solidworks.I have imported an assembly from solidworks into sim mechanics so I can create a controller for the assembly. The problem is simulink doesn’t seem to recognize the "Slot Mate" from Solidworks. I have imported an assembly from solidworks into sim mechanics so I can create a controller for the assembly. The problem is simulink doesn’t seem to recognize the "Slot Mate" from Solidworks. simulink, simscape, solidworks, mate, slot mate, export, advanced mating in solidworks, simscape multibodylink MATLAB Answers — New Questions
It is difficult to control the range
Hellow there. I want to connect functions with different scopes, but it doesn’t work. Where did I go wrong? Have a nice day everyone
here is my code
clc; clear all; close all;
A = readmatrix(‘w10_data.xlsx’,’Sheet’,’Sheet1′);
x = A(:,1);
fx = A(:,2);
%1D linear interpolation
xspace = [];
px = [];
for i = 1:3
x_segment = linspace(x(i), x(i+1),101);
p_segment = fx(i) + (fx(i+1) – fx(i))/(x(i+1)-x(i))*(x_segment-x(i));
xspace = [xspace x_segment(1:end-1)];
px = [px p_segment(1:end-1)];
end
% Polynomial interpolation
xspace2 = 4:0.01:7;
Lx = zeros(1,length(xspace2));
for j = 1:size(x,1)
lj = 1;
for m = 1:size(x,1)
if m == j
continue
end
lj = lj .*(xspace2 -x(m))/((x(j)-x(m)));
end
Lx = Lx + fx(j)*lj;
end
% Cubic spline interpolation
xspace3 = 7:0.01:10;
S = spline(x(7:end),fx(7:end),xspace3);
%S = spline(x,fx,xspace2);
figure(1)
scatter(x,fx,’k’,’filled’); hold on;
plot(xspace,px,’b’); hold on;
plot(xspace2,Lx,’r’); hold on;
plot(xspace2,S,’g’); hold on;
xlim([0 12]);
ylim([0 20]);Hellow there. I want to connect functions with different scopes, but it doesn’t work. Where did I go wrong? Have a nice day everyone
here is my code
clc; clear all; close all;
A = readmatrix(‘w10_data.xlsx’,’Sheet’,’Sheet1′);
x = A(:,1);
fx = A(:,2);
%1D linear interpolation
xspace = [];
px = [];
for i = 1:3
x_segment = linspace(x(i), x(i+1),101);
p_segment = fx(i) + (fx(i+1) – fx(i))/(x(i+1)-x(i))*(x_segment-x(i));
xspace = [xspace x_segment(1:end-1)];
px = [px p_segment(1:end-1)];
end
% Polynomial interpolation
xspace2 = 4:0.01:7;
Lx = zeros(1,length(xspace2));
for j = 1:size(x,1)
lj = 1;
for m = 1:size(x,1)
if m == j
continue
end
lj = lj .*(xspace2 -x(m))/((x(j)-x(m)));
end
Lx = Lx + fx(j)*lj;
end
% Cubic spline interpolation
xspace3 = 7:0.01:10;
S = spline(x(7:end),fx(7:end),xspace3);
%S = spline(x,fx,xspace2);
figure(1)
scatter(x,fx,’k’,’filled’); hold on;
plot(xspace,px,’b’); hold on;
plot(xspace2,Lx,’r’); hold on;
plot(xspace2,S,’g’); hold on;
xlim([0 12]);
ylim([0 20]); Hellow there. I want to connect functions with different scopes, but it doesn’t work. Where did I go wrong? Have a nice day everyone
here is my code
clc; clear all; close all;
A = readmatrix(‘w10_data.xlsx’,’Sheet’,’Sheet1′);
x = A(:,1);
fx = A(:,2);
%1D linear interpolation
xspace = [];
px = [];
for i = 1:3
x_segment = linspace(x(i), x(i+1),101);
p_segment = fx(i) + (fx(i+1) – fx(i))/(x(i+1)-x(i))*(x_segment-x(i));
xspace = [xspace x_segment(1:end-1)];
px = [px p_segment(1:end-1)];
end
% Polynomial interpolation
xspace2 = 4:0.01:7;
Lx = zeros(1,length(xspace2));
for j = 1:size(x,1)
lj = 1;
for m = 1:size(x,1)
if m == j
continue
end
lj = lj .*(xspace2 -x(m))/((x(j)-x(m)));
end
Lx = Lx + fx(j)*lj;
end
% Cubic spline interpolation
xspace3 = 7:0.01:10;
S = spline(x(7:end),fx(7:end),xspace3);
%S = spline(x,fx,xspace2);
figure(1)
scatter(x,fx,’k’,’filled’); hold on;
plot(xspace,px,’b’); hold on;
plot(xspace2,Lx,’r’); hold on;
plot(xspace2,S,’g’); hold on;
xlim([0 12]);
ylim([0 20]); matlab code MATLAB Answers — New Questions
how can i free the port to be used when fopen a udp by function fopen
when i run the ocde :
obj.m_udp = udp(192.168.1.1,’RemotePort’,50001,’LocalPort’,50002);
fopen(obj.m_udp);
then a error in command view:
error: icinterface/fopen
Unsuccessful open: Address already in use: Cannot bindwhen i run the ocde :
obj.m_udp = udp(192.168.1.1,’RemotePort’,50001,’LocalPort’,50002);
fopen(obj.m_udp);
then a error in command view:
error: icinterface/fopen
Unsuccessful open: Address already in use: Cannot bind when i run the ocde :
obj.m_udp = udp(192.168.1.1,’RemotePort’,50001,’LocalPort’,50002);
fopen(obj.m_udp);
then a error in command view:
error: icinterface/fopen
Unsuccessful open: Address already in use: Cannot bind udp,, unsuccessful open: address already in use: cannot MATLAB Answers — New Questions
I am working on SoC block set communication examples, specifically AD9361. I am getting the errors when I run the simulinkexamples
I am getting the folloing error "Error:Unable to log output of ‘soc_ADSB_sw/Task Manager’, port ‘1’. You cannot log function-call signals, action signals, state signals, or signals that feed into a Merge block." for the folloing example "openExample(‘soc/PacketBasedADSBTransceiverExample’). And I am unable to download the following example " openExample(‘xilinxsoc/TransmitAndReceiveTonesUsingAD9361DualChannelsExample’)" i am getting the following error" Error using findExample Unable to find "xilinxsoc/TransmitAndReceiveTonesUsingAD9361DualChannelsExample". Check theexample name and try again..
I am using Matlab 2023bI am getting the folloing error "Error:Unable to log output of ‘soc_ADSB_sw/Task Manager’, port ‘1’. You cannot log function-call signals, action signals, state signals, or signals that feed into a Merge block." for the folloing example "openExample(‘soc/PacketBasedADSBTransceiverExample’). And I am unable to download the following example " openExample(‘xilinxsoc/TransmitAndReceiveTonesUsingAD9361DualChannelsExample’)" i am getting the following error" Error using findExample Unable to find "xilinxsoc/TransmitAndReceiveTonesUsingAD9361DualChannelsExample". Check theexample name and try again..
I am using Matlab 2023b I am getting the folloing error "Error:Unable to log output of ‘soc_ADSB_sw/Task Manager’, port ‘1’. You cannot log function-call signals, action signals, state signals, or signals that feed into a Merge block." for the folloing example "openExample(‘soc/PacketBasedADSBTransceiverExample’). And I am unable to download the following example " openExample(‘xilinxsoc/TransmitAndReceiveTonesUsingAD9361DualChannelsExample’)" i am getting the following error" Error using findExample Unable to find "xilinxsoc/TransmitAndReceiveTonesUsingAD9361DualChannelsExample". Check theexample name and try again..
I am using Matlab 2023b soc block set, simulink, ad9361, fmcomms2, zedboard MATLAB Answers — New Questions
ZEDBOARD UART-USB matlab setup on linux
hello i am new to zedboard and am trying to set up the hardware since the past few weeks so any help would be great. i am trying to connect the board to the development computer
matlab version-R2022b
os-Ubuntu 20.04.3 LTS
i have used HDL Coder Support Package for Xilinx Zynq Platform
i keep getting this error and im not sure how to resolve it
any and all help would be appreciated thank you
———————————————————————————————————
attempts done:
1)i have tried to setup serial port using s=serialport(‘dev/ttyACM0’,115200); fopen(s) then tried the hardware
2)i have given permissions for dev/ttyACM0 by chmod 666
3)i have used putty to communicate with the zynq boardhello i am new to zedboard and am trying to set up the hardware since the past few weeks so any help would be great. i am trying to connect the board to the development computer
matlab version-R2022b
os-Ubuntu 20.04.3 LTS
i have used HDL Coder Support Package for Xilinx Zynq Platform
i keep getting this error and im not sure how to resolve it
any and all help would be appreciated thank you
———————————————————————————————————
attempts done:
1)i have tried to setup serial port using s=serialport(‘dev/ttyACM0’,115200); fopen(s) then tried the hardware
2)i have given permissions for dev/ttyACM0 by chmod 666
3)i have used putty to communicate with the zynq board hello i am new to zedboard and am trying to set up the hardware since the past few weeks so any help would be great. i am trying to connect the board to the development computer
matlab version-R2022b
os-Ubuntu 20.04.3 LTS
i have used HDL Coder Support Package for Xilinx Zynq Platform
i keep getting this error and im not sure how to resolve it
any and all help would be appreciated thank you
———————————————————————————————————
attempts done:
1)i have tried to setup serial port using s=serialport(‘dev/ttyACM0’,115200); fopen(s) then tried the hardware
2)i have given permissions for dev/ttyACM0 by chmod 666
3)i have used putty to communicate with the zynq board #uart-usb, #zedboard, #hdlcoder, zynq MATLAB Answers — New Questions