Tag Archives: matlab
Extracting Data from an Array of Arrays using a Loop?
Hello All,
Context: I am using Simulink and Simscape to simulate some system responses to motion. Simulation output writes to the Matlab workspace to an Array of Arrays (object maybe? Not super sure if that’s the right nomenclature) called "out". Our model is set up such that it iterates over a range of values for a single parameter. One test might have 5 iterations, the next might have 50, and so on. This means "out" changes size each time we run our model.
Problem: Now on to the issue. I am trying to extract data from each iteration and put them all into a Matrix. I can access all the data I want manually, using the notation "out(1,1).RollAngle.Data" for the first iteration, "out(1,2).RollAngle.Data" for the second iteration, and so on. However, this is too cumbersome since most of our tests are going to have 20-plus iterations.
Can anybody help me create a for loop that would append each data series as a new column in a matrix? This might be super obvious, but it’s a new problem for me…
Thanks!Hello All,
Context: I am using Simulink and Simscape to simulate some system responses to motion. Simulation output writes to the Matlab workspace to an Array of Arrays (object maybe? Not super sure if that’s the right nomenclature) called "out". Our model is set up such that it iterates over a range of values for a single parameter. One test might have 5 iterations, the next might have 50, and so on. This means "out" changes size each time we run our model.
Problem: Now on to the issue. I am trying to extract data from each iteration and put them all into a Matrix. I can access all the data I want manually, using the notation "out(1,1).RollAngle.Data" for the first iteration, "out(1,2).RollAngle.Data" for the second iteration, and so on. However, this is too cumbersome since most of our tests are going to have 20-plus iterations.
Can anybody help me create a for loop that would append each data series as a new column in a matrix? This might be super obvious, but it’s a new problem for me…
Thanks! Hello All,
Context: I am using Simulink and Simscape to simulate some system responses to motion. Simulation output writes to the Matlab workspace to an Array of Arrays (object maybe? Not super sure if that’s the right nomenclature) called "out". Our model is set up such that it iterates over a range of values for a single parameter. One test might have 5 iterations, the next might have 50, and so on. This means "out" changes size each time we run our model.
Problem: Now on to the issue. I am trying to extract data from each iteration and put them all into a Matrix. I can access all the data I want manually, using the notation "out(1,1).RollAngle.Data" for the first iteration, "out(1,2).RollAngle.Data" for the second iteration, and so on. However, this is too cumbersome since most of our tests are going to have 20-plus iterations.
Can anybody help me create a for loop that would append each data series as a new column in a matrix? This might be super obvious, but it’s a new problem for me…
Thanks! arrays, simulation output, append data to matrix, matlab MATLAB Answers — New Questions
Inverter DC Capacitor Voltage Control
Using PI to control the DC capacitor voltage of the inverter, but there are pulses from 0.4 seconds. I don’t know what the cause is.Using PI to control the DC capacitor voltage of the inverter, but there are pulses from 0.4 seconds. I don’t know what the cause is. Using PI to control the DC capacitor voltage of the inverter, but there are pulses from 0.4 seconds. I don’t know what the cause is. inverter MATLAB Answers — New Questions
How to speed up my code (computing jacobian)
My input are a lot of linear expressions such as x1+x2, x2+3*x3 etc. How to speed up my code as follows
allvars = symvar(input); % There are about 1000 LINEAR expressions in ‘input’
J = jacobian(input, allvars);My input are a lot of linear expressions such as x1+x2, x2+3*x3 etc. How to speed up my code as follows
allvars = symvar(input); % There are about 1000 LINEAR expressions in ‘input’
J = jacobian(input, allvars); My input are a lot of linear expressions such as x1+x2, x2+3*x3 etc. How to speed up my code as follows
allvars = symvar(input); % There are about 1000 LINEAR expressions in ‘input’
J = jacobian(input, allvars); symbolic, linear, matlab MATLAB Answers — New Questions
Merge multiple files containing given string into one mat file
Hello,
How to merge multiple files which names contains given strings (for instance: Name, ECG, data) into one file?Hello,
How to merge multiple files which names contains given strings (for instance: Name, ECG, data) into one file? Hello,
How to merge multiple files which names contains given strings (for instance: Name, ECG, data) into one file? merge multiple files containing given string into MATLAB Answers — New Questions
How to solve this error?
I keep getting this error while running the state space model,
Error in port widths or dimensions. Output port 1 of ‘statespacemodel_hvm/Mux’ is a one dimensional vector with 2 elements.
Error in port widths or dimensions. Input port 1 of ‘statespacemodel_hvm/State-Space’ has 3 elements. This port does not accept the dimensions (or orientation) specified by the input signal.
Please help me with this.I keep getting this error while running the state space model,
Error in port widths or dimensions. Output port 1 of ‘statespacemodel_hvm/Mux’ is a one dimensional vector with 2 elements.
Error in port widths or dimensions. Input port 1 of ‘statespacemodel_hvm/State-Space’ has 3 elements. This port does not accept the dimensions (or orientation) specified by the input signal.
Please help me with this. I keep getting this error while running the state space model,
Error in port widths or dimensions. Output port 1 of ‘statespacemodel_hvm/Mux’ is a one dimensional vector with 2 elements.
Error in port widths or dimensions. Input port 1 of ‘statespacemodel_hvm/State-Space’ has 3 elements. This port does not accept the dimensions (or orientation) specified by the input signal.
Please help me with this. error MATLAB Answers — New Questions
i need help to find the mathematical equation that can made this model in pic (how can convert pressure drop to air velocity (dp to Vx) in modeling of OWC
Post Content Post Content in modeling of owc MATLAB Answers — New Questions
Best/Cleanest way to select a specific sheet from an excel file?
I am importing an excel file that has multiple sheets. I am using the readtable command to import the file. For the sheet choice, I am giving the read table command the ‘Sheet’ modifier with the sheet name.
My question is about getting the sheet name. Currently, I have the "sheetnames" command get a string array of the sheet names, then I use "listdlg" to display them and return a selection. the listdlg command is just not the best though. The formatting does not look very good, and I have multiple monitors. It does not pop up on the same monitor or the previously used monitor. It always pops up on the first, which if you need to run the program many times quickly, means you have to move across all monitors to select an option. Is there a better way to format it or an alternative to the "listdlg"?
Is there a different way of doing all of this that is better than sheetnames and listdlg? My program I’ve written pretty heavily relies on "readtable", so I cannot change that aspect.
% get the file name and file path of the selected excel file
[fileName,pathName] = uigetfile(‘*xlsx;*.xls’,’Select the Excel file’);
% check if user canceled file selection and act accordingly
if fileName == 0
return;
end
% combine the file name and file path to get the complete file path of the
% selected excel file
completeTableFilePath = fullfile(pathName,fileName);
% gather the names of all the sheets of the excel file
sheetNamesArray = sheetnames(completeTableFilePath);
% create a dialog box that lists all the sheet names in the file and
% prompts the user to pick one
sheetChoice = listdlg(‘PromptString’,’Select the sheet:’,’SelectionMode’,’single’,’ListString’,sheetNamesArray);
% check if user canceled file selection
if isempty(sheetChoice)
return;
end
% remembers the index of the selected excel sheet
sheetChoiceFileName = sheetNamesArray(sheetChoice);
% intake the specific sheet of the selected excel file as strings
inputTable = readtable(completeTableFilePath,’Sheet’,sheetChoiceFileName,’TextType’,’string’);I am importing an excel file that has multiple sheets. I am using the readtable command to import the file. For the sheet choice, I am giving the read table command the ‘Sheet’ modifier with the sheet name.
My question is about getting the sheet name. Currently, I have the "sheetnames" command get a string array of the sheet names, then I use "listdlg" to display them and return a selection. the listdlg command is just not the best though. The formatting does not look very good, and I have multiple monitors. It does not pop up on the same monitor or the previously used monitor. It always pops up on the first, which if you need to run the program many times quickly, means you have to move across all monitors to select an option. Is there a better way to format it or an alternative to the "listdlg"?
Is there a different way of doing all of this that is better than sheetnames and listdlg? My program I’ve written pretty heavily relies on "readtable", so I cannot change that aspect.
% get the file name and file path of the selected excel file
[fileName,pathName] = uigetfile(‘*xlsx;*.xls’,’Select the Excel file’);
% check if user canceled file selection and act accordingly
if fileName == 0
return;
end
% combine the file name and file path to get the complete file path of the
% selected excel file
completeTableFilePath = fullfile(pathName,fileName);
% gather the names of all the sheets of the excel file
sheetNamesArray = sheetnames(completeTableFilePath);
% create a dialog box that lists all the sheet names in the file and
% prompts the user to pick one
sheetChoice = listdlg(‘PromptString’,’Select the sheet:’,’SelectionMode’,’single’,’ListString’,sheetNamesArray);
% check if user canceled file selection
if isempty(sheetChoice)
return;
end
% remembers the index of the selected excel sheet
sheetChoiceFileName = sheetNamesArray(sheetChoice);
% intake the specific sheet of the selected excel file as strings
inputTable = readtable(completeTableFilePath,’Sheet’,sheetChoiceFileName,’TextType’,’string’); I am importing an excel file that has multiple sheets. I am using the readtable command to import the file. For the sheet choice, I am giving the read table command the ‘Sheet’ modifier with the sheet name.
My question is about getting the sheet name. Currently, I have the "sheetnames" command get a string array of the sheet names, then I use "listdlg" to display them and return a selection. the listdlg command is just not the best though. The formatting does not look very good, and I have multiple monitors. It does not pop up on the same monitor or the previously used monitor. It always pops up on the first, which if you need to run the program many times quickly, means you have to move across all monitors to select an option. Is there a better way to format it or an alternative to the "listdlg"?
Is there a different way of doing all of this that is better than sheetnames and listdlg? My program I’ve written pretty heavily relies on "readtable", so I cannot change that aspect.
% get the file name and file path of the selected excel file
[fileName,pathName] = uigetfile(‘*xlsx;*.xls’,’Select the Excel file’);
% check if user canceled file selection and act accordingly
if fileName == 0
return;
end
% combine the file name and file path to get the complete file path of the
% selected excel file
completeTableFilePath = fullfile(pathName,fileName);
% gather the names of all the sheets of the excel file
sheetNamesArray = sheetnames(completeTableFilePath);
% create a dialog box that lists all the sheet names in the file and
% prompts the user to pick one
sheetChoice = listdlg(‘PromptString’,’Select the sheet:’,’SelectionMode’,’single’,’ListString’,sheetNamesArray);
% check if user canceled file selection
if isempty(sheetChoice)
return;
end
% remembers the index of the selected excel sheet
sheetChoiceFileName = sheetNamesArray(sheetChoice);
% intake the specific sheet of the selected excel file as strings
inputTable = readtable(completeTableFilePath,’Sheet’,sheetChoiceFileName,’TextType’,’string’); listdlg, importing excel data, performance, gui MATLAB Answers — New Questions
Concatenate name fields in nested structure
Hello,
I am trying to save value of the data placed in the last fields in nested structure by concatenating string in recursion. The name of the file should string composed of the all preceding fields in structure.
However I am not able to save previous fields.
The code is as follows:
nameDataBase = ‘database.mat’;
structNest = load([pathFolder, nameDataBase]);
structFields = myIsField(structNest, ‘data’);
pathOutputFile = pathFolder;
fileName = ”
function isFieldResult = myIsField (inStruct, fieldName)
% inStruct is the name of the structure or an array of structures to search
% fieldName is the name of the field for which the function searches
B = struct();
display(‘output folder’)
isFieldResult = 0;
f = fieldnames(inStruct(1))
f1 = string(fieldnames(inStruct(1)))
for i=1:1%length(f)
display("i")
i
if(strcmp(f{i},strtrim(fieldName)))
isFieldResult = 1;
display(‘data found – end’)
B.(f{i}) = inStruct(1).(f{i})
data = getfield(B,’data’)
return;
elseif isstruct(inStruct(1).(f{i}))
isFieldResult = myIsField(inStruct(1).(f{i}), fieldName);
B.(f{i}) = inStruct(1).(f{i})
if isFieldResult
display(‘time found -loop’)
return;
end
end
endHello,
I am trying to save value of the data placed in the last fields in nested structure by concatenating string in recursion. The name of the file should string composed of the all preceding fields in structure.
However I am not able to save previous fields.
The code is as follows:
nameDataBase = ‘database.mat’;
structNest = load([pathFolder, nameDataBase]);
structFields = myIsField(structNest, ‘data’);
pathOutputFile = pathFolder;
fileName = ”
function isFieldResult = myIsField (inStruct, fieldName)
% inStruct is the name of the structure or an array of structures to search
% fieldName is the name of the field for which the function searches
B = struct();
display(‘output folder’)
isFieldResult = 0;
f = fieldnames(inStruct(1))
f1 = string(fieldnames(inStruct(1)))
for i=1:1%length(f)
display("i")
i
if(strcmp(f{i},strtrim(fieldName)))
isFieldResult = 1;
display(‘data found – end’)
B.(f{i}) = inStruct(1).(f{i})
data = getfield(B,’data’)
return;
elseif isstruct(inStruct(1).(f{i}))
isFieldResult = myIsField(inStruct(1).(f{i}), fieldName);
B.(f{i}) = inStruct(1).(f{i})
if isFieldResult
display(‘time found -loop’)
return;
end
end
end Hello,
I am trying to save value of the data placed in the last fields in nested structure by concatenating string in recursion. The name of the file should string composed of the all preceding fields in structure.
However I am not able to save previous fields.
The code is as follows:
nameDataBase = ‘database.mat’;
structNest = load([pathFolder, nameDataBase]);
structFields = myIsField(structNest, ‘data’);
pathOutputFile = pathFolder;
fileName = ”
function isFieldResult = myIsField (inStruct, fieldName)
% inStruct is the name of the structure or an array of structures to search
% fieldName is the name of the field for which the function searches
B = struct();
display(‘output folder’)
isFieldResult = 0;
f = fieldnames(inStruct(1))
f1 = string(fieldnames(inStruct(1)))
for i=1:1%length(f)
display("i")
i
if(strcmp(f{i},strtrim(fieldName)))
isFieldResult = 1;
display(‘data found – end’)
B.(f{i}) = inStruct(1).(f{i})
data = getfield(B,’data’)
return;
elseif isstruct(inStruct(1).(f{i}))
isFieldResult = myIsField(inStruct(1).(f{i}), fieldName);
B.(f{i}) = inStruct(1).(f{i})
if isFieldResult
display(‘time found -loop’)
return;
end
end
end concatenate name fields in nested structure MATLAB Answers — New Questions
Accessing a full PDF of tasks and answers of ONRAMP
Is there anyway I can have a full text of the answers to the tasks completed in the ONRAMP course? Just so I can print it and keep it with me and go through the things I have learnt without restarting a while module and going through the tasks again?Is there anyway I can have a full text of the answers to the tasks completed in the ONRAMP course? Just so I can print it and keep it with me and go through the things I have learnt without restarting a while module and going through the tasks again? Is there anyway I can have a full text of the answers to the tasks completed in the ONRAMP course? Just so I can print it and keep it with me and go through the things I have learnt without restarting a while module and going through the tasks again? answers, pdf, course, access, homework, download MATLAB Answers — New Questions
command line vs GUI, toolbox failed
I am running a script on R2024a via command line and i have got this error:
cmd: matlab -nodisplay -nosplash -nodesktop -r "run(‘my_script.m’); exit;"
error: niftiinfo requires Image Processing Toolbox.
Of course i have Image Processing Toolbox already in the toolbox folder. In fact, when i run same script from the GUI, everything is going well. The path is correctly set otherwise even the GUI has to fail.
Someone has an idea?
ThanksI am running a script on R2024a via command line and i have got this error:
cmd: matlab -nodisplay -nosplash -nodesktop -r "run(‘my_script.m’); exit;"
error: niftiinfo requires Image Processing Toolbox.
Of course i have Image Processing Toolbox already in the toolbox folder. In fact, when i run same script from the GUI, everything is going well. The path is correctly set otherwise even the GUI has to fail.
Someone has an idea?
Thanks I am running a script on R2024a via command line and i have got this error:
cmd: matlab -nodisplay -nosplash -nodesktop -r "run(‘my_script.m’); exit;"
error: niftiinfo requires Image Processing Toolbox.
Of course i have Image Processing Toolbox already in the toolbox folder. In fact, when i run same script from the GUI, everything is going well. The path is correctly set otherwise even the GUI has to fail.
Someone has an idea?
Thanks command line, toolbox MATLAB Answers — New Questions
no standalone apps output in console
I have function:
function m = magicsquare1(n)
%MAGICSQUARE generates a magic square matrix of the size
% specified by the input parameter n.
% Copyright 2003-2012 The MathWorks, Inc.
if ischar(n)
n=str2num(n);
end
m = magic(n);
>> magicsquare1(5)
ans =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
The standalone application is created by
>> mcc -mv magicsquare1.m
(of course MCR is properly installed and configured)
Then the standalone application "magicsquare1" does not produce any output in command-line console!!! But it should, according to the help page of MATLAB compiler.
When I change the function like this:
function m = magicsquare2(n)
%MAGICSQUARE generates a magic square matrix of the size
% specified by the input parameter n.
% Copyright 2003-2012 The MathWorks, Inc.
if ischar(n)
n=str2num(n);
end
m = magic(n);
disp(m);
and recompile by
>>mcc -mv magicsquare2.m
I am able to get correct output.
>> !magicsquare2 5
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
So my question is: what is wrong? Why I am not able to get output from standalone application magicsquare1?I have function:
function m = magicsquare1(n)
%MAGICSQUARE generates a magic square matrix of the size
% specified by the input parameter n.
% Copyright 2003-2012 The MathWorks, Inc.
if ischar(n)
n=str2num(n);
end
m = magic(n);
>> magicsquare1(5)
ans =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
The standalone application is created by
>> mcc -mv magicsquare1.m
(of course MCR is properly installed and configured)
Then the standalone application "magicsquare1" does not produce any output in command-line console!!! But it should, according to the help page of MATLAB compiler.
When I change the function like this:
function m = magicsquare2(n)
%MAGICSQUARE generates a magic square matrix of the size
% specified by the input parameter n.
% Copyright 2003-2012 The MathWorks, Inc.
if ischar(n)
n=str2num(n);
end
m = magic(n);
disp(m);
and recompile by
>>mcc -mv magicsquare2.m
I am able to get correct output.
>> !magicsquare2 5
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
So my question is: what is wrong? Why I am not able to get output from standalone application magicsquare1? I have function:
function m = magicsquare1(n)
%MAGICSQUARE generates a magic square matrix of the size
% specified by the input parameter n.
% Copyright 2003-2012 The MathWorks, Inc.
if ischar(n)
n=str2num(n);
end
m = magic(n);
>> magicsquare1(5)
ans =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
The standalone application is created by
>> mcc -mv magicsquare1.m
(of course MCR is properly installed and configured)
Then the standalone application "magicsquare1" does not produce any output in command-line console!!! But it should, according to the help page of MATLAB compiler.
When I change the function like this:
function m = magicsquare2(n)
%MAGICSQUARE generates a magic square matrix of the size
% specified by the input parameter n.
% Copyright 2003-2012 The MathWorks, Inc.
if ischar(n)
n=str2num(n);
end
m = magic(n);
disp(m);
and recompile by
>>mcc -mv magicsquare2.m
I am able to get correct output.
>> !magicsquare2 5
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
So my question is: what is wrong? Why I am not able to get output from standalone application magicsquare1? console apps MATLAB Answers — New Questions
How can I get a shapley summary plot?
I have checekd the MATLAB syntaxes about the shapley value plots, but the examples didn’t help me figure out how I can sketch a shapley summary plot similar to the attached image. Can you please help me out?
In python, you can use shap libraries to understand how much each input variable in the machine learning model contributes to the model prediction. But, I’m not able to have that flexibility in MATLAB.
Ref:https://towardsdatascience.com/explain-your-model-with-the-shap-values-bc36aac4de3dI have checekd the MATLAB syntaxes about the shapley value plots, but the examples didn’t help me figure out how I can sketch a shapley summary plot similar to the attached image. Can you please help me out?
In python, you can use shap libraries to understand how much each input variable in the machine learning model contributes to the model prediction. But, I’m not able to have that flexibility in MATLAB.
Ref:https://towardsdatascience.com/explain-your-model-with-the-shap-values-bc36aac4de3d I have checekd the MATLAB syntaxes about the shapley value plots, but the examples didn’t help me figure out how I can sketch a shapley summary plot similar to the attached image. Can you please help me out?
In python, you can use shap libraries to understand how much each input variable in the machine learning model contributes to the model prediction. But, I’m not able to have that flexibility in MATLAB.
Ref:https://towardsdatascience.com/explain-your-model-with-the-shap-values-bc36aac4de3d machine learning, shapley values MATLAB Answers — New Questions
modify v1 so that any value less than 4 is replaced with the value 0. Please help me making code.
modify v1 so that any value less than 4 is replaced with the value 0. please help me writing code.modify v1 so that any value less than 4 is replaced with the value 0. please help me writing code. modify v1 so that any value less than 4 is replaced with the value 0. please help me writing code. logical indexing MATLAB Answers — New Questions
Matlab Online Cannot “Open” Simulink File
Trying to open a Simulink file on Matlab Online causes a browser error, and the screen will be stuck with a loading circle, as shown in the picture above. The browser error is invisible to the user unless browser’s console is open. I hope the error in the picture will help the Matlab’s team to diagnose the problem. There are also a number of fetching errors to some US-east server that are not shown in the picture.
The issue can be replicated across Edge, Chrome, and Firefox.
It is currently impossible to load a simulink file from the computer unless the engineers figure out what the problem is. Is there a way for instructors to upload an online template and assign to students, which the students can retrieve and then modify?Trying to open a Simulink file on Matlab Online causes a browser error, and the screen will be stuck with a loading circle, as shown in the picture above. The browser error is invisible to the user unless browser’s console is open. I hope the error in the picture will help the Matlab’s team to diagnose the problem. There are also a number of fetching errors to some US-east server that are not shown in the picture.
The issue can be replicated across Edge, Chrome, and Firefox.
It is currently impossible to load a simulink file from the computer unless the engineers figure out what the problem is. Is there a way for instructors to upload an online template and assign to students, which the students can retrieve and then modify? Trying to open a Simulink file on Matlab Online causes a browser error, and the screen will be stuck with a loading circle, as shown in the picture above. The browser error is invisible to the user unless browser’s console is open. I hope the error in the picture will help the Matlab’s team to diagnose the problem. There are also a number of fetching errors to some US-east server that are not shown in the picture.
The issue can be replicated across Edge, Chrome, and Firefox.
It is currently impossible to load a simulink file from the computer unless the engineers figure out what the problem is. Is there a way for instructors to upload an online template and assign to students, which the students can retrieve and then modify? matlab online, simulink online MATLAB Answers — New Questions
Disp function with matlab coder
I’m experimenting with a simple hello world function to see how the coder works.
disp(‘Hello world’)
The mex version works, but when I make a standalone executable there is no output. In fact, the generated code for the function itself is completely empty ({}), like the disp() was purposely skipped over. Is this the expected behavior, or is there some setting I can change?
EDIT: I just tried fprintf(1,’Hello world’), and the converted code contains "cfprintf()". So still, purposely suppressing output? BTW, this is on Linux/2016b.I’m experimenting with a simple hello world function to see how the coder works.
disp(‘Hello world’)
The mex version works, but when I make a standalone executable there is no output. In fact, the generated code for the function itself is completely empty ({}), like the disp() was purposely skipped over. Is this the expected behavior, or is there some setting I can change?
EDIT: I just tried fprintf(1,’Hello world’), and the converted code contains "cfprintf()". So still, purposely suppressing output? BTW, this is on Linux/2016b. I’m experimenting with a simple hello world function to see how the coder works.
disp(‘Hello world’)
The mex version works, but when I make a standalone executable there is no output. In fact, the generated code for the function itself is completely empty ({}), like the disp() was purposely skipped over. Is this the expected behavior, or is there some setting I can change?
EDIT: I just tried fprintf(1,’Hello world’), and the converted code contains "cfprintf()". So still, purposely suppressing output? BTW, this is on Linux/2016b. matlab coder MATLAB Answers — New Questions
How to convert *.pth file to *.onnx?
Hi,
I used Pointpillars for 3D object detection on my own dataset (just using *.bin files and their *.txt labels) using Pytorch (Cuda). The format of the trained model is *.pth. I would like to convert the *.pth file to *.onnx format. I think I should define a model (Pointpillars) and a dummy tensor/input in this regard. I am not sure how to define them. Is there any MATLAB example/library in this regard?
I appreciate any help in advance.
Thank you,
AbbasHi,
I used Pointpillars for 3D object detection on my own dataset (just using *.bin files and their *.txt labels) using Pytorch (Cuda). The format of the trained model is *.pth. I would like to convert the *.pth file to *.onnx format. I think I should define a model (Pointpillars) and a dummy tensor/input in this regard. I am not sure how to define them. Is there any MATLAB example/library in this regard?
I appreciate any help in advance.
Thank you,
Abbas Hi,
I used Pointpillars for 3D object detection on my own dataset (just using *.bin files and their *.txt labels) using Pytorch (Cuda). The format of the trained model is *.pth. I would like to convert the *.pth file to *.onnx format. I think I should define a model (Pointpillars) and a dummy tensor/input in this regard. I am not sure how to define them. Is there any MATLAB example/library in this regard?
I appreciate any help in advance.
Thank you,
Abbas pth, onnx, pointpillars MATLAB Answers — New Questions
How to set parameters in an FMU from Matlab Simulink ?
We have an FMU developed using MSVC 2022 for Windows x64. The FMU imports in Simulink nicely and I am able to see the I/O ports as intended. I am also able to access the inputs set from the environment using assigning a constant / signal generator to the input ports.
I would now like to also set the parameters from the workspace. I have tried using several of the callback functions at the model (Simulink) level as well as the block level. However, I am still not able to see the supplied values affect the parameter values inside the FMU. I am testing this by logging the output in various functions. I only want to set the parameters once at the start of simulation and they are defined like so in the modelDescription.xml file:
<Float64 name="LP" valueReference="1" causality="parameter" variability="fixed" initial="exact" description="POS_THICKNESS" declaredType="Length" start=".1320e-3" />
While the default value is already set, we would like the end user to be able to configure it once for every run.
Any guidance with how to debug this would be appreciated.We have an FMU developed using MSVC 2022 for Windows x64. The FMU imports in Simulink nicely and I am able to see the I/O ports as intended. I am also able to access the inputs set from the environment using assigning a constant / signal generator to the input ports.
I would now like to also set the parameters from the workspace. I have tried using several of the callback functions at the model (Simulink) level as well as the block level. However, I am still not able to see the supplied values affect the parameter values inside the FMU. I am testing this by logging the output in various functions. I only want to set the parameters once at the start of simulation and they are defined like so in the modelDescription.xml file:
<Float64 name="LP" valueReference="1" causality="parameter" variability="fixed" initial="exact" description="POS_THICKNESS" declaredType="Length" start=".1320e-3" />
While the default value is already set, we would like the end user to be able to configure it once for every run.
Any guidance with how to debug this would be appreciated. We have an FMU developed using MSVC 2022 for Windows x64. The FMU imports in Simulink nicely and I am able to see the I/O ports as intended. I am also able to access the inputs set from the environment using assigning a constant / signal generator to the input ports.
I would now like to also set the parameters from the workspace. I have tried using several of the callback functions at the model (Simulink) level as well as the block level. However, I am still not able to see the supplied values affect the parameter values inside the FMU. I am testing this by logging the output in various functions. I only want to set the parameters once at the start of simulation and they are defined like so in the modelDescription.xml file:
<Float64 name="LP" valueReference="1" causality="parameter" variability="fixed" initial="exact" description="POS_THICKNESS" declaredType="Length" start=".1320e-3" />
While the default value is already set, we would like the end user to be able to configure it once for every run.
Any guidance with how to debug this would be appreciated. fmu, co-simulation, simulink MATLAB Answers — New Questions
how to calculate a derivative
can some one guide me how to calculate a derivative and integration in matlab . can you please give a little example.can some one guide me how to calculate a derivative and integration in matlab . can you please give a little example. can some one guide me how to calculate a derivative and integration in matlab . can you please give a little example. derivative and integration MATLAB Answers — New Questions
how to create a matrix with variables in it?
for eg., to create following matrix and work on it,
A=[x1 x1*x2 ; x1^2 x2^2]for eg., to create following matrix and work on it,
A=[x1 x1*x2 ; x1^2 x2^2] for eg., to create following matrix and work on it,
A=[x1 x1*x2 ; x1^2 x2^2] variable matrix MATLAB Answers — New Questions
How to draw free-hand sketches using imfreehand ?
I have to take as input hand drawn sketches … I have tried using imfreehand() but it completes the figures itself.
I also tried the solution provided by Doug Schwarz in
<http://www.mathworks.in/matlabcentral/newsreader/view_thread/30168#75552>
where he coded the following :
function sketch(cmd)
if nargin == 0
cmd = ‘init’;
end
switch cmd
case ‘init’
fig = figure(‘DoubleBuffer’,’on’,’back’,’off’);
info.ax = axes(‘XLim’,[0 1],’YLim’,[0 1]);
info.drawing = [];
info.x = [];
info.y = [];
set(fig,’UserData’,info,…
‘WindowButtonDownFcn’,[mfilename,’ down’])
case ‘down’
myname = mfilename;
fig = gcbf;
info = get(fig,’UserData’);
curpos = get(info.ax,’CurrentPoint’);
info.x = curpos(1,1);
info.y = curpos(1,2);
info.drawing = line(info.x,info.y,’Color’,’k’);
set(fig,’UserData’,info,…
‘WindowButtonMotionFcn’,[myname,’ move’],…
‘WindowButtonUpFcn’,[myname,’ up’])
case ‘move’
fig = gcbf;
info = get(fig,’UserData’);
curpos = get(info.ax,’CurrentPoint’);
info.x = [info.x;curpos(1,1)];
info.y = [info.y;curpos(1,2)];
set(info.drawing,’XData’,info.x,’YData’,info.y)
set(fig,’UserData’,info)
case ‘up’
fig = gcbf;
set(fig,’WindowButtonMotionFcn’,”,…
‘WindowButtonUpFcn’,”)
end
But I am not able to save the sketch being drawn or access it ..
Please help …I have to take as input hand drawn sketches … I have tried using imfreehand() but it completes the figures itself.
I also tried the solution provided by Doug Schwarz in
<http://www.mathworks.in/matlabcentral/newsreader/view_thread/30168#75552>
where he coded the following :
function sketch(cmd)
if nargin == 0
cmd = ‘init’;
end
switch cmd
case ‘init’
fig = figure(‘DoubleBuffer’,’on’,’back’,’off’);
info.ax = axes(‘XLim’,[0 1],’YLim’,[0 1]);
info.drawing = [];
info.x = [];
info.y = [];
set(fig,’UserData’,info,…
‘WindowButtonDownFcn’,[mfilename,’ down’])
case ‘down’
myname = mfilename;
fig = gcbf;
info = get(fig,’UserData’);
curpos = get(info.ax,’CurrentPoint’);
info.x = curpos(1,1);
info.y = curpos(1,2);
info.drawing = line(info.x,info.y,’Color’,’k’);
set(fig,’UserData’,info,…
‘WindowButtonMotionFcn’,[myname,’ move’],…
‘WindowButtonUpFcn’,[myname,’ up’])
case ‘move’
fig = gcbf;
info = get(fig,’UserData’);
curpos = get(info.ax,’CurrentPoint’);
info.x = [info.x;curpos(1,1)];
info.y = [info.y;curpos(1,2)];
set(info.drawing,’XData’,info.x,’YData’,info.y)
set(fig,’UserData’,info)
case ‘up’
fig = gcbf;
set(fig,’WindowButtonMotionFcn’,”,…
‘WindowButtonUpFcn’,”)
end
But I am not able to save the sketch being drawn or access it ..
Please help … I have to take as input hand drawn sketches … I have tried using imfreehand() but it completes the figures itself.
I also tried the solution provided by Doug Schwarz in
<http://www.mathworks.in/matlabcentral/newsreader/view_thread/30168#75552>
where he coded the following :
function sketch(cmd)
if nargin == 0
cmd = ‘init’;
end
switch cmd
case ‘init’
fig = figure(‘DoubleBuffer’,’on’,’back’,’off’);
info.ax = axes(‘XLim’,[0 1],’YLim’,[0 1]);
info.drawing = [];
info.x = [];
info.y = [];
set(fig,’UserData’,info,…
‘WindowButtonDownFcn’,[mfilename,’ down’])
case ‘down’
myname = mfilename;
fig = gcbf;
info = get(fig,’UserData’);
curpos = get(info.ax,’CurrentPoint’);
info.x = curpos(1,1);
info.y = curpos(1,2);
info.drawing = line(info.x,info.y,’Color’,’k’);
set(fig,’UserData’,info,…
‘WindowButtonMotionFcn’,[myname,’ move’],…
‘WindowButtonUpFcn’,[myname,’ up’])
case ‘move’
fig = gcbf;
info = get(fig,’UserData’);
curpos = get(info.ax,’CurrentPoint’);
info.x = [info.x;curpos(1,1)];
info.y = [info.y;curpos(1,2)];
set(info.drawing,’XData’,info.x,’YData’,info.y)
set(fig,’UserData’,info)
case ‘up’
fig = gcbf;
set(fig,’WindowButtonMotionFcn’,”,…
‘WindowButtonUpFcn’,”)
end
But I am not able to save the sketch being drawn or access it ..
Please help … freehand sketch MATLAB Answers — New Questions