Category: Matlab
Category Archives: Matlab
Inconsistent pressure, enthalpy and entropy from thermodynamic properties sensor and pressure sensor compared with CoolProp
I’m looking at the reversible heat pump example found here:
https://www.mathworks.com/help/hydro/ug/ReversibleHeatPumpExample.html
I run the example as-is, and then look at results in Simscape results explorer, focusing on three values calculated within S1: pressure from the Saturation Properties Sensor and enthalpy and entropy from the Thermodynamic Properties Sensor. I then move those plots to a figure and highlight three values at a single time:
The simulink model results give P=0.845676 MPa, H=423.098kJ/kg and S=1.87762kJ/kgK
However, when I use CoolProp within matlab to calculate entropy at the pressure and enthalpy combination I get a different value than given by the saturation properties sensor:
py.CoolProp.CoolProp.PropsSI(‘S’, ‘P’, 0.845676e6, ‘H’, 423.098*1e3, ‘R410A’)/1000
ans =
1.8113
Why is CoolProp giving 1.8113kJ/kgK but the thermodynamic properties sensor is giving 1.87762kJ/kgK?I’m looking at the reversible heat pump example found here:
https://www.mathworks.com/help/hydro/ug/ReversibleHeatPumpExample.html
I run the example as-is, and then look at results in Simscape results explorer, focusing on three values calculated within S1: pressure from the Saturation Properties Sensor and enthalpy and entropy from the Thermodynamic Properties Sensor. I then move those plots to a figure and highlight three values at a single time:
The simulink model results give P=0.845676 MPa, H=423.098kJ/kg and S=1.87762kJ/kgK
However, when I use CoolProp within matlab to calculate entropy at the pressure and enthalpy combination I get a different value than given by the saturation properties sensor:
py.CoolProp.CoolProp.PropsSI(‘S’, ‘P’, 0.845676e6, ‘H’, 423.098*1e3, ‘R410A’)/1000
ans =
1.8113
Why is CoolProp giving 1.8113kJ/kgK but the thermodynamic properties sensor is giving 1.87762kJ/kgK? I’m looking at the reversible heat pump example found here:
https://www.mathworks.com/help/hydro/ug/ReversibleHeatPumpExample.html
I run the example as-is, and then look at results in Simscape results explorer, focusing on three values calculated within S1: pressure from the Saturation Properties Sensor and enthalpy and entropy from the Thermodynamic Properties Sensor. I then move those plots to a figure and highlight three values at a single time:
The simulink model results give P=0.845676 MPa, H=423.098kJ/kg and S=1.87762kJ/kgK
However, when I use CoolProp within matlab to calculate entropy at the pressure and enthalpy combination I get a different value than given by the saturation properties sensor:
py.CoolProp.CoolProp.PropsSI(‘S’, ‘P’, 0.845676e6, ‘H’, 423.098*1e3, ‘R410A’)/1000
ans =
1.8113
Why is CoolProp giving 1.8113kJ/kgK but the thermodynamic properties sensor is giving 1.87762kJ/kgK? simulink, fluid properties, saturation properties sensor, entropy MATLAB Answers — New Questions
File Exchange can’t use the publish functionality?
For the past two months at any time I haven’t been able to use FEX’s ‘publish’ feature. After clicking that button, a popup appears saying:
‘The application is currently unavailable.
We’ve been notified of the issue and are looking into it.’
Has anyone else had the same problem as me?
I’m currently in Mainland China; with or without VPN, switching regions, it always shows this error. The browser I’m using is the latest version of Microsoft Edge.”For the past two months at any time I haven’t been able to use FEX’s ‘publish’ feature. After clicking that button, a popup appears saying:
‘The application is currently unavailable.
We’ve been notified of the issue and are looking into it.’
Has anyone else had the same problem as me?
I’m currently in Mainland China; with or without VPN, switching regions, it always shows this error. The browser I’m using is the latest version of Microsoft Edge.” For the past two months at any time I haven’t been able to use FEX’s ‘publish’ feature. After clicking that button, a popup appears saying:
‘The application is currently unavailable.
We’ve been notified of the issue and are looking into it.’
Has anyone else had the same problem as me?
I’m currently in Mainland China; with or without VPN, switching regions, it always shows this error. The browser I’m using is the latest version of Microsoft Edge.” publish, fex, web MATLAB Answers — New Questions
2 area bus system
I’m unable to find Kundur bus system file.I’m unable to find Kundur bus system file. I’m unable to find Kundur bus system file. kundur-two-area-bus-system MATLAB Answers — New Questions
Dependency analyzer refuses to work
I have tried to run the Dependency Analyzer from the Apps tab countless times and it has only worked once. I didn’t do anything differently from the previous and next attempt, it just randomly worked. I have tried selecting individual files and whole folders. It shows it’s analyzing each item, then throws an error and says it’s "Updating the graph" forever and all you can do is close the window.
I’ve tried reinstalling and updating Matlab, running as administrator, trying different file types, etc. all to no avail.I have tried to run the Dependency Analyzer from the Apps tab countless times and it has only worked once. I didn’t do anything differently from the previous and next attempt, it just randomly worked. I have tried selecting individual files and whole folders. It shows it’s analyzing each item, then throws an error and says it’s "Updating the graph" forever and all you can do is close the window.
I’ve tried reinstalling and updating Matlab, running as administrator, trying different file types, etc. all to no avail. I have tried to run the Dependency Analyzer from the Apps tab countless times and it has only worked once. I didn’t do anything differently from the previous and next attempt, it just randomly worked. I have tried selecting individual files and whole folders. It shows it’s analyzing each item, then throws an error and says it’s "Updating the graph" forever and all you can do is close the window.
I’ve tried reinstalling and updating Matlab, running as administrator, trying different file types, etc. all to no avail. error MATLAB Answers — New Questions
LSTM network time series prediction error occurs at the initial time step
I have trained a LSTM network for time series regression. After training, I want to test its performance based on the test dataset. The testing result of one single sample (extracted from minibatch results) is shown as follows:
The prediction result has a transient response process. I think this issue is caused by the zero states (CellStates and HiddenStates) of LSTM netweok. How to resolve this zero states problem when predicting time sreries ?I have trained a LSTM network for time series regression. After training, I want to test its performance based on the test dataset. The testing result of one single sample (extracted from minibatch results) is shown as follows:
The prediction result has a transient response process. I think this issue is caused by the zero states (CellStates and HiddenStates) of LSTM netweok. How to resolve this zero states problem when predicting time sreries ? I have trained a LSTM network for time series regression. After training, I want to test its performance based on the test dataset. The testing result of one single sample (extracted from minibatch results) is shown as follows:
The prediction result has a transient response process. I think this issue is caused by the zero states (CellStates and HiddenStates) of LSTM netweok. How to resolve this zero states problem when predicting time sreries ? lstm, deep learning, time series MATLAB Answers — New Questions
How to approach iterative data reading?
I’m working with a dataset that has 3 different arrays I’m interested in plotting: time, accel, and gcamp. They are all of equal size.
I’m using the accel variable as a threshold detector, where I define an arbitrary threshold under which any data I ignore. Anything above that threshold I use the index of that data point to grab the equivalent data points from time and gcamp.
How can I store this data in one structure so that I can iterate through it and generate statistics/plots about only the thresholded data points?
Something like:
time = [rand(1, 5000)];
accel = [rand(1,5000)];
gcamp = [rand(1,5000)];
sd = std(accel);
threshold = sd;
dumb = [];
for i = 1:length(accel);
if accel(i) > threshold;
dumber = [time(i), gcamp(i)];
dumb = [dumb, dumber];
end
endI’m working with a dataset that has 3 different arrays I’m interested in plotting: time, accel, and gcamp. They are all of equal size.
I’m using the accel variable as a threshold detector, where I define an arbitrary threshold under which any data I ignore. Anything above that threshold I use the index of that data point to grab the equivalent data points from time and gcamp.
How can I store this data in one structure so that I can iterate through it and generate statistics/plots about only the thresholded data points?
Something like:
time = [rand(1, 5000)];
accel = [rand(1,5000)];
gcamp = [rand(1,5000)];
sd = std(accel);
threshold = sd;
dumb = [];
for i = 1:length(accel);
if accel(i) > threshold;
dumber = [time(i), gcamp(i)];
dumb = [dumb, dumber];
end
end I’m working with a dataset that has 3 different arrays I’m interested in plotting: time, accel, and gcamp. They are all of equal size.
I’m using the accel variable as a threshold detector, where I define an arbitrary threshold under which any data I ignore. Anything above that threshold I use the index of that data point to grab the equivalent data points from time and gcamp.
How can I store this data in one structure so that I can iterate through it and generate statistics/plots about only the thresholded data points?
Something like:
time = [rand(1, 5000)];
accel = [rand(1,5000)];
gcamp = [rand(1,5000)];
sd = std(accel);
threshold = sd;
dumb = [];
for i = 1:length(accel);
if accel(i) > threshold;
dumber = [time(i), gcamp(i)];
dumb = [dumb, dumber];
end
end for loop, storing data MATLAB Answers — New Questions
Data Processing in a Cell
Hello,
I have imported data into two tables T1 and T2 34243X4 and 1070X8. To Compare the two tables I have padded T2 with string ’empty’ in all columns to match rows of T1. I am comparing T2(:,2) with T1(:,1) and which ever matches I then automatically the that particular row element in 4th Col of T2 will match row element of 1st Col in T1 (This acts as Sanity Check).
All the info in both the table is in string format including numbers
when I tried to use ismember is not able to match.
Did String Compare is not working or not comaring correctly.
Please could someone guide me. I have attached my code/script and also screenshots of my data.
Thank you for your time
PN = importdata("Part Number Summary 20260220.xlsx");
opts = detectImportOptions("Sai_MFGParts_03202026_v2.xlsx", Sheet="Export Worksheet");
% Adjust options if needed, for example set data range:
opts.DataRange = "A2";
T1 = readtable("Sai_MFGParts_03202026_v2.xlsx",opts);
T2 = PN.Summary;
C = T2; % rename for clarity
headers = C(1,1:8);
data = C(2:end,1:8);
varNames = matlab.lang.makeValidName(headers);
T2 = cell2table(data, ‘VariableNames’, varNames);
Part_Number_Data_T2 = T2.PartNumber;
Product_Description_T2 = T2.ProductDescription;
Supplier_T2 = T2.Supplier;
Categoty_T2 = T2.Category;
idx = length(T1.BWC_PART);
Part_Number_Data_T2 = resize(Part_Number_Data_T2,idx); % resize to match T1(34243×4)
Product_Description_T2 = resize(Product_Description_T2,idx);
Supplier_T2 = resize(Supplier_T2,idx);
Categoty_T2 = resize(Categoty_T2,idx);
idx_2 = cellfun(‘isempty’,Part_Number_Data_T2);
idx_3 = cellfun(‘isempty’,Product_Description_T2);
idx_4 = cellfun(‘isempty’,Supplier_T2);
idx_5 = cellfun(‘isempty’,Categoty_T2);
%Replace empty entries in Product_Description_T2, Supplier_T2, and
%Categoty_T2 with string ’empty’.
Part_Number_Data_T2(idx_2) = {’empty’};
Product_Description_T2(idx_3) = {’empty’};
Supplier_T2(idx_4) = {’empty’};
Categoty_T2(idx_5) = {’empty’};
%Ensure T2 columns are column vectors
Part_Number_Data_T2 = Part_Number_Data_T2(:);
Product_Description_T2 = Product_Description_T2(:);
Supplier_T2 = Supplier_T2(:);
Categoty_T2 = Categoty_T2(:);
Ind = cell(size(T1.BWC_PART));
for k = 1:length(Ind)
Ind{k} = T1(strcmp(T1.BWC_PART,Part_Number_Data_T2{k}),:);
endHello,
I have imported data into two tables T1 and T2 34243X4 and 1070X8. To Compare the two tables I have padded T2 with string ’empty’ in all columns to match rows of T1. I am comparing T2(:,2) with T1(:,1) and which ever matches I then automatically the that particular row element in 4th Col of T2 will match row element of 1st Col in T1 (This acts as Sanity Check).
All the info in both the table is in string format including numbers
when I tried to use ismember is not able to match.
Did String Compare is not working or not comaring correctly.
Please could someone guide me. I have attached my code/script and also screenshots of my data.
Thank you for your time
PN = importdata("Part Number Summary 20260220.xlsx");
opts = detectImportOptions("Sai_MFGParts_03202026_v2.xlsx", Sheet="Export Worksheet");
% Adjust options if needed, for example set data range:
opts.DataRange = "A2";
T1 = readtable("Sai_MFGParts_03202026_v2.xlsx",opts);
T2 = PN.Summary;
C = T2; % rename for clarity
headers = C(1,1:8);
data = C(2:end,1:8);
varNames = matlab.lang.makeValidName(headers);
T2 = cell2table(data, ‘VariableNames’, varNames);
Part_Number_Data_T2 = T2.PartNumber;
Product_Description_T2 = T2.ProductDescription;
Supplier_T2 = T2.Supplier;
Categoty_T2 = T2.Category;
idx = length(T1.BWC_PART);
Part_Number_Data_T2 = resize(Part_Number_Data_T2,idx); % resize to match T1(34243×4)
Product_Description_T2 = resize(Product_Description_T2,idx);
Supplier_T2 = resize(Supplier_T2,idx);
Categoty_T2 = resize(Categoty_T2,idx);
idx_2 = cellfun(‘isempty’,Part_Number_Data_T2);
idx_3 = cellfun(‘isempty’,Product_Description_T2);
idx_4 = cellfun(‘isempty’,Supplier_T2);
idx_5 = cellfun(‘isempty’,Categoty_T2);
%Replace empty entries in Product_Description_T2, Supplier_T2, and
%Categoty_T2 with string ’empty’.
Part_Number_Data_T2(idx_2) = {’empty’};
Product_Description_T2(idx_3) = {’empty’};
Supplier_T2(idx_4) = {’empty’};
Categoty_T2(idx_5) = {’empty’};
%Ensure T2 columns are column vectors
Part_Number_Data_T2 = Part_Number_Data_T2(:);
Product_Description_T2 = Product_Description_T2(:);
Supplier_T2 = Supplier_T2(:);
Categoty_T2 = Categoty_T2(:);
Ind = cell(size(T1.BWC_PART));
for k = 1:length(Ind)
Ind{k} = T1(strcmp(T1.BWC_PART,Part_Number_Data_T2{k}),:);
end Hello,
I have imported data into two tables T1 and T2 34243X4 and 1070X8. To Compare the two tables I have padded T2 with string ’empty’ in all columns to match rows of T1. I am comparing T2(:,2) with T1(:,1) and which ever matches I then automatically the that particular row element in 4th Col of T2 will match row element of 1st Col in T1 (This acts as Sanity Check).
All the info in both the table is in string format including numbers
when I tried to use ismember is not able to match.
Did String Compare is not working or not comaring correctly.
Please could someone guide me. I have attached my code/script and also screenshots of my data.
Thank you for your time
PN = importdata("Part Number Summary 20260220.xlsx");
opts = detectImportOptions("Sai_MFGParts_03202026_v2.xlsx", Sheet="Export Worksheet");
% Adjust options if needed, for example set data range:
opts.DataRange = "A2";
T1 = readtable("Sai_MFGParts_03202026_v2.xlsx",opts);
T2 = PN.Summary;
C = T2; % rename for clarity
headers = C(1,1:8);
data = C(2:end,1:8);
varNames = matlab.lang.makeValidName(headers);
T2 = cell2table(data, ‘VariableNames’, varNames);
Part_Number_Data_T2 = T2.PartNumber;
Product_Description_T2 = T2.ProductDescription;
Supplier_T2 = T2.Supplier;
Categoty_T2 = T2.Category;
idx = length(T1.BWC_PART);
Part_Number_Data_T2 = resize(Part_Number_Data_T2,idx); % resize to match T1(34243×4)
Product_Description_T2 = resize(Product_Description_T2,idx);
Supplier_T2 = resize(Supplier_T2,idx);
Categoty_T2 = resize(Categoty_T2,idx);
idx_2 = cellfun(‘isempty’,Part_Number_Data_T2);
idx_3 = cellfun(‘isempty’,Product_Description_T2);
idx_4 = cellfun(‘isempty’,Supplier_T2);
idx_5 = cellfun(‘isempty’,Categoty_T2);
%Replace empty entries in Product_Description_T2, Supplier_T2, and
%Categoty_T2 with string ’empty’.
Part_Number_Data_T2(idx_2) = {’empty’};
Product_Description_T2(idx_3) = {’empty’};
Supplier_T2(idx_4) = {’empty’};
Categoty_T2(idx_5) = {’empty’};
%Ensure T2 columns are column vectors
Part_Number_Data_T2 = Part_Number_Data_T2(:);
Product_Description_T2 = Product_Description_T2(:);
Supplier_T2 = Supplier_T2(:);
Categoty_T2 = Categoty_T2(:);
Ind = cell(size(T1.BWC_PART));
for k = 1:length(Ind)
Ind{k} = T1(strcmp(T1.BWC_PART,Part_Number_Data_T2{k}),:);
end matlab, data processing MATLAB Answers — New Questions
How do I integrate MATLAB and Simulink Online Courses?
I would like to integrate the self-paced courses for MATLAB and Simulink with a Learning Management System (LMS), how can I do so?I would like to integrate the self-paced courses for MATLAB and Simulink with a Learning Management System (LMS), how can I do so? I would like to integrate the self-paced courses for MATLAB and Simulink with a Learning Management System (LMS), how can I do so? MATLAB Answers — New Questions
Why are my MATLAB preferences not included during compilation in R2022a and later?
I have code that relies on a proxy setting included in my MATLAB preferences. In R2021b and earlier releases, this would automatically be included in packaging when compiling this code with MATLAB Compiler or MATLAB Compiler SDK. However, in R2022a and later, this no longer seems to be the case.
Why are my MATLAB preferences no longer being included when compiling code for deployment?I have code that relies on a proxy setting included in my MATLAB preferences. In R2021b and earlier releases, this would automatically be included in packaging when compiling this code with MATLAB Compiler or MATLAB Compiler SDK. However, in R2022a and later, this no longer seems to be the case.
Why are my MATLAB preferences no longer being included when compiling code for deployment? I have code that relies on a proxy setting included in my MATLAB preferences. In R2021b and earlier releases, this would automatically be included in packaging when compiling this code with MATLAB Compiler or MATLAB Compiler SDK. However, in R2022a and later, this no longer seems to be the case.
Why are my MATLAB preferences no longer being included when compiling code for deployment? proxy MATLAB Answers — New Questions
Requirements toolbox : How to add custom attribute from new column import from Excel file.
Hi everybody,
I am using the Requirement toolbox (R2023b update 4), importing requirements from excel (.xlsx file).
I followed the Mathworks example to make a first import with custom import options (as custom attributes), then i used to update from the requirements GUI after modifying requirements in the excel file (Click on Import file, and click "Update" on Requirement Interchange tab).
My problem is I need to add a column inside my Excel file, and a new custom attribute corresponding inside the .slreq file.
I cannot find how to change the import options as the requirement file already exists without importing a hole new requirement set so I will loose every links and update changes traceability.
Could you help me to find a way to change those options si when I Update the requirement set, the new custom attribute is added from the new column without breaking all my links ?
Thank you so much in advance!
Hope this find you well.Hi everybody,
I am using the Requirement toolbox (R2023b update 4), importing requirements from excel (.xlsx file).
I followed the Mathworks example to make a first import with custom import options (as custom attributes), then i used to update from the requirements GUI after modifying requirements in the excel file (Click on Import file, and click "Update" on Requirement Interchange tab).
My problem is I need to add a column inside my Excel file, and a new custom attribute corresponding inside the .slreq file.
I cannot find how to change the import options as the requirement file already exists without importing a hole new requirement set so I will loose every links and update changes traceability.
Could you help me to find a way to change those options si when I Update the requirement set, the new custom attribute is added from the new column without breaking all my links ?
Thank you so much in advance!
Hope this find you well. Hi everybody,
I am using the Requirement toolbox (R2023b update 4), importing requirements from excel (.xlsx file).
I followed the Mathworks example to make a first import with custom import options (as custom attributes), then i used to update from the requirements GUI after modifying requirements in the excel file (Click on Import file, and click "Update" on Requirement Interchange tab).
My problem is I need to add a column inside my Excel file, and a new custom attribute corresponding inside the .slreq file.
I cannot find how to change the import options as the requirement file already exists without importing a hole new requirement set so I will loose every links and update changes traceability.
Could you help me to find a way to change those options si when I Update the requirement set, the new custom attribute is added from the new column without breaking all my links ?
Thank you so much in advance!
Hope this find you well. requirements, requirements toolbox, import options, matlab MATLAB Answers — New Questions
Why does MATLAB sporadically crash on my 13th or 14th generation Intel processor?
Why does MATLAB crash sporadically on my 13th or 14th generation Intel CPU but not on other machines? The crash log frequently is different each time, and the same code works fine on other computers.Why does MATLAB crash sporadically on my 13th or 14th generation Intel CPU but not on other machines? The crash log frequently is different each time, and the same code works fine on other computers. Why does MATLAB crash sporadically on my 13th or 14th generation Intel CPU but not on other machines? The crash log frequently is different each time, and the same code works fine on other computers. crash, intel, raptorlake MATLAB Answers — New Questions
How do I enable license borrowing for a network license?
How do I enable license borrowing for my network license?How do I enable license borrowing for my network license? How do I enable license borrowing for my network license? MATLAB Answers — New Questions
unrecognized date format from “dir” command for french users with july month
Hi Guys,
I have 2024b version and encountered a bug that was not here on previous version.
dir command generates a date (last modification on the file) for any file like ’26-sept.-2018 16:52:18′
then when using datenum or datevec on this output, it returns a correct date transformation.
However when the date includes month of july like this:
’17-juil.-2023 10:29:58′ (french abbreviation for july month)
datenum could not recognized this entry as a valid date.
Error message is:
Error using datenum (line 200)
Failed to convert input to date numbers.
Caused by:
Unable to perform assignment because the left and right sides have a different number of elements.
it works well for every french abbreviation of all months except for july.Hi Guys,
I have 2024b version and encountered a bug that was not here on previous version.
dir command generates a date (last modification on the file) for any file like ’26-sept.-2018 16:52:18′
then when using datenum or datevec on this output, it returns a correct date transformation.
However when the date includes month of july like this:
’17-juil.-2023 10:29:58′ (french abbreviation for july month)
datenum could not recognized this entry as a valid date.
Error message is:
Error using datenum (line 200)
Failed to convert input to date numbers.
Caused by:
Unable to perform assignment because the left and right sides have a different number of elements.
it works well for every french abbreviation of all months except for july. Hi Guys,
I have 2024b version and encountered a bug that was not here on previous version.
dir command generates a date (last modification on the file) for any file like ’26-sept.-2018 16:52:18′
then when using datenum or datevec on this output, it returns a correct date transformation.
However when the date includes month of july like this:
’17-juil.-2023 10:29:58′ (french abbreviation for july month)
datenum could not recognized this entry as a valid date.
Error message is:
Error using datenum (line 200)
Failed to convert input to date numbers.
Caused by:
Unable to perform assignment because the left and right sides have a different number of elements.
it works well for every french abbreviation of all months except for july. date format MATLAB Answers — New Questions
listdlg in MATLAB R2025b returns selected indices in click order instead of ascending order
In MATLAB R2025b, listdlg appears to return the selected indices in the order the user clicked them, rather than in ascending numeric order.
In older versions such as R2022b and R2024a, the returned indices were ordered ascendingly, which made the behavior predictable and easy to work with in downstream code.
This change caused nasty bugs in existing code on my side, because I use the returned indices to index into related lists that assume a consistent ascending order. With the new behavior, the item order can differ depending on click sequence, which breaks code that previously worked correctly.
Minimal example:
[idx, tf] = listdlg( …
‘ListString’, {‘A’,’B’,’C’,’D’,’E’}, …
‘SelectionMode’, ‘multiple’);
disp(idx)
In R2025b, if I click items in the order 2, 1, 3, the result is: [2 1 3] -> Which leads to calling [‘B’, ‘A’, ‘C’] in downstream code
Whereas in older releases it was always: [1 2 3]
Questions:
Is this behavior change intentional in R2025b? I cannot find any documentation on that.
Is there a way to restore the old ascending-order behavior globally, for example via a preference or in startup.m?
Or is the only safe solution now to wrap every listdlg call with sort(idx) manually?
I can work around this with sort, but it would be very helpful if there were a default compatibility option, especially for larger existing codebases.In MATLAB R2025b, listdlg appears to return the selected indices in the order the user clicked them, rather than in ascending numeric order.
In older versions such as R2022b and R2024a, the returned indices were ordered ascendingly, which made the behavior predictable and easy to work with in downstream code.
This change caused nasty bugs in existing code on my side, because I use the returned indices to index into related lists that assume a consistent ascending order. With the new behavior, the item order can differ depending on click sequence, which breaks code that previously worked correctly.
Minimal example:
[idx, tf] = listdlg( …
‘ListString’, {‘A’,’B’,’C’,’D’,’E’}, …
‘SelectionMode’, ‘multiple’);
disp(idx)
In R2025b, if I click items in the order 2, 1, 3, the result is: [2 1 3] -> Which leads to calling [‘B’, ‘A’, ‘C’] in downstream code
Whereas in older releases it was always: [1 2 3]
Questions:
Is this behavior change intentional in R2025b? I cannot find any documentation on that.
Is there a way to restore the old ascending-order behavior globally, for example via a preference or in startup.m?
Or is the only safe solution now to wrap every listdlg call with sort(idx) manually?
I can work around this with sort, but it would be very helpful if there were a default compatibility option, especially for larger existing codebases. In MATLAB R2025b, listdlg appears to return the selected indices in the order the user clicked them, rather than in ascending numeric order.
In older versions such as R2022b and R2024a, the returned indices were ordered ascendingly, which made the behavior predictable and easy to work with in downstream code.
This change caused nasty bugs in existing code on my side, because I use the returned indices to index into related lists that assume a consistent ascending order. With the new behavior, the item order can differ depending on click sequence, which breaks code that previously worked correctly.
Minimal example:
[idx, tf] = listdlg( …
‘ListString’, {‘A’,’B’,’C’,’D’,’E’}, …
‘SelectionMode’, ‘multiple’);
disp(idx)
In R2025b, if I click items in the order 2, 1, 3, the result is: [2 1 3] -> Which leads to calling [‘B’, ‘A’, ‘C’] in downstream code
Whereas in older releases it was always: [1 2 3]
Questions:
Is this behavior change intentional in R2025b? I cannot find any documentation on that.
Is there a way to restore the old ascending-order behavior globally, for example via a preference or in startup.m?
Or is the only safe solution now to wrap every listdlg call with sort(idx) manually?
I can work around this with sort, but it would be very helpful if there were a default compatibility option, especially for larger existing codebases. listdlg, order, click, user MATLAB Answers — New Questions
Can I use the Simulink Solver profiler programmatically?
I want to view Solver Profiler output for a variety of Simulink simulations, and currently I am running them one by one in the Solver Profiler window to achieve this. I would like to batch run them overnight and view profiler results afterwards, is this possible?I want to view Solver Profiler output for a variety of Simulink simulations, and currently I am running them one by one in the Solver Profiler window to achieve this. I would like to batch run them overnight and view profiler results afterwards, is this possible? I want to view Solver Profiler output for a variety of Simulink simulations, and currently I am running them one by one in the Solver Profiler window to achieve this. I would like to batch run them overnight and view profiler results afterwards, is this possible? simulink profiler, command line MATLAB Answers — New Questions
Allocating parameters to ramfuncs section
I need to execute parts of my code on the C2000 from RAM. I was able to generate code from my subsystem into a non‑reusable, standalone function and copy that function to RAM. I also need to copy some of the parameters used by this function into RAM so they can execute more quickly.
Paragraph 7 of the following document attempts to describe the process, but it does not provide enough detail to follow:
Load Data/Code to Flash and Run from RAM on TI C2000 – MATLAB & Simulink
Could you provide guidance and a step‑by‑step explanation of how to perform this operation?I need to execute parts of my code on the C2000 from RAM. I was able to generate code from my subsystem into a non‑reusable, standalone function and copy that function to RAM. I also need to copy some of the parameters used by this function into RAM so they can execute more quickly.
Paragraph 7 of the following document attempts to describe the process, but it does not provide enough detail to follow:
Load Data/Code to Flash and Run from RAM on TI C2000 – MATLAB & Simulink
Could you provide guidance and a step‑by‑step explanation of how to perform this operation? I need to execute parts of my code on the C2000 from RAM. I was able to generate code from my subsystem into a non‑reusable, standalone function and copy that function to RAM. I also need to copy some of the parameters used by this function into RAM so they can execute more quickly.
Paragraph 7 of the following document attempts to describe the process, but it does not provide enough detail to follow:
Load Data/Code to Flash and Run from RAM on TI C2000 – MATLAB & Simulink
Could you provide guidance and a step‑by‑step explanation of how to perform this operation? c2000, simulink MATLAB Answers — New Questions
Is it possible to switch MATLAB versions after launching via the MATLAB .NET Engine API?
I want to launch MATLAB via the .NET Engine API from a C# application to run my Simulink models. My Simulink models are created using a variety of MATLAB versions (e.g., R2023b and R2025b). Can my C# application launch an instance of R2023b using the MATLAB .NET Engine API, perform some processing, close R2023b, and then launch an R2025b instance?I want to launch MATLAB via the .NET Engine API from a C# application to run my Simulink models. My Simulink models are created using a variety of MATLAB versions (e.g., R2023b and R2025b). Can my C# application launch an instance of R2023b using the MATLAB .NET Engine API, perform some processing, close R2023b, and then launch an R2025b instance? I want to launch MATLAB via the .NET Engine API from a C# application to run my Simulink models. My Simulink models are created using a variety of MATLAB versions (e.g., R2023b and R2025b). Can my C# application launch an instance of R2023b using the MATLAB .NET Engine API, perform some processing, close R2023b, and then launch an R2025b instance? .net, c#, engine, api, multiple, multi MATLAB Answers — New Questions
How to use the nonlinear least square fitting to fit a transfer function?How to improve the fitting accuracy
I have a dataset Y representing the real part Y(:,1) and the imaginary part (Y:,2) of a function against the frequency fq. I want to find the coefficient of the transfer function to have the a good fit with the dataset. The transfer function is given assumed to have a fifth order, (so there are totally 10 unknowns) T(p,q,s)=p(5)*s^4+p(4)*s^3+p(3)*s^2+p(2)*s+p(1))/(s^5+q(5)*s^4+q(4)*s^3+q(3)*s^2+q(2)*s+q(1));
The code is given in the attached, I split the objective function as the imaginary and real part respectively, the objective function is (real(T)-Y(:,1))^2+(imag(T)-Y(:,2)) over all the selected points in the Y-fq curve.
The blue circle is the fitted result from the NLSQ, but they are slightly away from the original data. My question is how to improve the code to improve the fitting result.
In the attached files,"nonlsqfitting.mat" is the Y and fq data; NLSFmat is the runing code; OBJrealimag.m is the objective function, where Yout(:,1) is the real part of T and Yout(:,2) is the imaginary part of T.I have a dataset Y representing the real part Y(:,1) and the imaginary part (Y:,2) of a function against the frequency fq. I want to find the coefficient of the transfer function to have the a good fit with the dataset. The transfer function is given assumed to have a fifth order, (so there are totally 10 unknowns) T(p,q,s)=p(5)*s^4+p(4)*s^3+p(3)*s^2+p(2)*s+p(1))/(s^5+q(5)*s^4+q(4)*s^3+q(3)*s^2+q(2)*s+q(1));
The code is given in the attached, I split the objective function as the imaginary and real part respectively, the objective function is (real(T)-Y(:,1))^2+(imag(T)-Y(:,2)) over all the selected points in the Y-fq curve.
The blue circle is the fitted result from the NLSQ, but they are slightly away from the original data. My question is how to improve the code to improve the fitting result.
In the attached files,"nonlsqfitting.mat" is the Y and fq data; NLSFmat is the runing code; OBJrealimag.m is the objective function, where Yout(:,1) is the real part of T and Yout(:,2) is the imaginary part of T. I have a dataset Y representing the real part Y(:,1) and the imaginary part (Y:,2) of a function against the frequency fq. I want to find the coefficient of the transfer function to have the a good fit with the dataset. The transfer function is given assumed to have a fifth order, (so there are totally 10 unknowns) T(p,q,s)=p(5)*s^4+p(4)*s^3+p(3)*s^2+p(2)*s+p(1))/(s^5+q(5)*s^4+q(4)*s^3+q(3)*s^2+q(2)*s+q(1));
The code is given in the attached, I split the objective function as the imaginary and real part respectively, the objective function is (real(T)-Y(:,1))^2+(imag(T)-Y(:,2)) over all the selected points in the Y-fq curve.
The blue circle is the fitted result from the NLSQ, but they are slightly away from the original data. My question is how to improve the code to improve the fitting result.
In the attached files,"nonlsqfitting.mat" is the Y and fq data; NLSFmat is the runing code; OBJrealimag.m is the objective function, where Yout(:,1) is the real part of T and Yout(:,2) is the imaginary part of T. nonlinear least square fitting transfer function MATLAB Answers — New Questions
Title is missing when saving a figure using print, saveas, exportgraphics, and printpreview
Context: When plotting images, I have often set the tick marks to face outward, where they are not obscured by the image. This change requires that I nudge the title upward by a small amount so that it is separated from the ticks.
Problem: When I save the file using print, saveas, exportgraphics or printpreview, the title is sometimes missing in the output file. (See attached examples above.)
I found that this problem occurs when the image is plotted using pcolor (and probably surf as well). It does not occur when using plot and imagesc. Annotation is used below to draw an outline of the outer extent of the figure. The nudged title clearly lies within that limit.
Work Around: The problem is fixed by ensuring that the Units property for the title is set to data after adjusting the title position. Note that I have filed a bug report with Matlab.
Versions: This problem did not occur with Matlab versions 2022a and earlier. It started with version 2022b and continues with version 2023a.
Coded example:
function test_figureTitleProblem
%… Simple demonstration of missing title problem.
% When plotting images, I have often set the tick marks to face outward,
% where they are not obscurved by the image. This change requires that
% I nudge the title upward by a small amount so that it is separated
% from the ticks.
%
% Problem: When I save the file using print, saveas, exportgraphics
% and printpreview, the title is missing in the output file.
% I found that this problem occurs when the image is plotted using
% pcolor, and does not occur when imagesc is used. I also found
% that the problem can be fixed by changing the Units property for the title
% back to data (see below). Annotation is used below to draw an outline of
% the outer extent of the figure. The nudged title clearly lies within
% that limit.
%% Initialize variables
%… Load Matlab’s global topographic data
load(‘topo.mat’, ‘topo’);
%… Create grid vectors
lon = 0:359;
lat = -89:90;
%% Plot
figure
%… Missing title occurs with pcolor, and not with imagesc
pcolor(lon, lat, topo)
shading interp
% imagesc(lon, lat, topo)
% axis xy
%… Format plot
hA = gca;
hA.Box = ‘on’;
hA.TickDir = ‘out’; % Oriented tick marks to face outward
hA.Layer = ‘top’; % Places grid lines and tick markers on top of image
hA.FontSize = 16;
hA.LineWidth = 1;
%… Render title, and nudge upward to separate from outward tick marks
hT = title(‘Demonstration of Demonstration of Missing Title’, ‘FontSize’, 16);
hT.Units = ‘normalized’;
hT.Position(2) = hT.Position(2) + 0.02;
% hT.Units = ‘data’; % Uncomment this line to fix problem
%… Draw rectangle to show outer limit for figure
annotation("rectangle", hA.OuterPosition, Color="red", LineWidth=1)
%… Start print preview to show that the title is missing
print(‘missingTitle_print.pdf’, ‘-dpdf’)
saveas(hA, ‘missingTitle_saveas.pdf’)
exportgraphics(hA, ‘missingTitle_exportgraphics.pdf’)
printpreview
endContext: When plotting images, I have often set the tick marks to face outward, where they are not obscured by the image. This change requires that I nudge the title upward by a small amount so that it is separated from the ticks.
Problem: When I save the file using print, saveas, exportgraphics or printpreview, the title is sometimes missing in the output file. (See attached examples above.)
I found that this problem occurs when the image is plotted using pcolor (and probably surf as well). It does not occur when using plot and imagesc. Annotation is used below to draw an outline of the outer extent of the figure. The nudged title clearly lies within that limit.
Work Around: The problem is fixed by ensuring that the Units property for the title is set to data after adjusting the title position. Note that I have filed a bug report with Matlab.
Versions: This problem did not occur with Matlab versions 2022a and earlier. It started with version 2022b and continues with version 2023a.
Coded example:
function test_figureTitleProblem
%… Simple demonstration of missing title problem.
% When plotting images, I have often set the tick marks to face outward,
% where they are not obscurved by the image. This change requires that
% I nudge the title upward by a small amount so that it is separated
% from the ticks.
%
% Problem: When I save the file using print, saveas, exportgraphics
% and printpreview, the title is missing in the output file.
% I found that this problem occurs when the image is plotted using
% pcolor, and does not occur when imagesc is used. I also found
% that the problem can be fixed by changing the Units property for the title
% back to data (see below). Annotation is used below to draw an outline of
% the outer extent of the figure. The nudged title clearly lies within
% that limit.
%% Initialize variables
%… Load Matlab’s global topographic data
load(‘topo.mat’, ‘topo’);
%… Create grid vectors
lon = 0:359;
lat = -89:90;
%% Plot
figure
%… Missing title occurs with pcolor, and not with imagesc
pcolor(lon, lat, topo)
shading interp
% imagesc(lon, lat, topo)
% axis xy
%… Format plot
hA = gca;
hA.Box = ‘on’;
hA.TickDir = ‘out’; % Oriented tick marks to face outward
hA.Layer = ‘top’; % Places grid lines and tick markers on top of image
hA.FontSize = 16;
hA.LineWidth = 1;
%… Render title, and nudge upward to separate from outward tick marks
hT = title(‘Demonstration of Demonstration of Missing Title’, ‘FontSize’, 16);
hT.Units = ‘normalized’;
hT.Position(2) = hT.Position(2) + 0.02;
% hT.Units = ‘data’; % Uncomment this line to fix problem
%… Draw rectangle to show outer limit for figure
annotation("rectangle", hA.OuterPosition, Color="red", LineWidth=1)
%… Start print preview to show that the title is missing
print(‘missingTitle_print.pdf’, ‘-dpdf’)
saveas(hA, ‘missingTitle_saveas.pdf’)
exportgraphics(hA, ‘missingTitle_exportgraphics.pdf’)
printpreview
end Context: When plotting images, I have often set the tick marks to face outward, where they are not obscured by the image. This change requires that I nudge the title upward by a small amount so that it is separated from the ticks.
Problem: When I save the file using print, saveas, exportgraphics or printpreview, the title is sometimes missing in the output file. (See attached examples above.)
I found that this problem occurs when the image is plotted using pcolor (and probably surf as well). It does not occur when using plot and imagesc. Annotation is used below to draw an outline of the outer extent of the figure. The nudged title clearly lies within that limit.
Work Around: The problem is fixed by ensuring that the Units property for the title is set to data after adjusting the title position. Note that I have filed a bug report with Matlab.
Versions: This problem did not occur with Matlab versions 2022a and earlier. It started with version 2022b and continues with version 2023a.
Coded example:
function test_figureTitleProblem
%… Simple demonstration of missing title problem.
% When plotting images, I have often set the tick marks to face outward,
% where they are not obscurved by the image. This change requires that
% I nudge the title upward by a small amount so that it is separated
% from the ticks.
%
% Problem: When I save the file using print, saveas, exportgraphics
% and printpreview, the title is missing in the output file.
% I found that this problem occurs when the image is plotted using
% pcolor, and does not occur when imagesc is used. I also found
% that the problem can be fixed by changing the Units property for the title
% back to data (see below). Annotation is used below to draw an outline of
% the outer extent of the figure. The nudged title clearly lies within
% that limit.
%% Initialize variables
%… Load Matlab’s global topographic data
load(‘topo.mat’, ‘topo’);
%… Create grid vectors
lon = 0:359;
lat = -89:90;
%% Plot
figure
%… Missing title occurs with pcolor, and not with imagesc
pcolor(lon, lat, topo)
shading interp
% imagesc(lon, lat, topo)
% axis xy
%… Format plot
hA = gca;
hA.Box = ‘on’;
hA.TickDir = ‘out’; % Oriented tick marks to face outward
hA.Layer = ‘top’; % Places grid lines and tick markers on top of image
hA.FontSize = 16;
hA.LineWidth = 1;
%… Render title, and nudge upward to separate from outward tick marks
hT = title(‘Demonstration of Demonstration of Missing Title’, ‘FontSize’, 16);
hT.Units = ‘normalized’;
hT.Position(2) = hT.Position(2) + 0.02;
% hT.Units = ‘data’; % Uncomment this line to fix problem
%… Draw rectangle to show outer limit for figure
annotation("rectangle", hA.OuterPosition, Color="red", LineWidth=1)
%… Start print preview to show that the title is missing
print(‘missingTitle_print.pdf’, ‘-dpdf’)
saveas(hA, ‘missingTitle_saveas.pdf’)
exportgraphics(hA, ‘missingTitle_exportgraphics.pdf’)
printpreview
end missing title MATLAB Answers — New Questions
Why am I receiving errors when reading and writing to an instrument with Instrument Control Toolbox R2024b?
I am connecting to my Windows 11 based Keysight oscilloscope and source via "visadev." I intermittently receive the following two errors when reading and writing to the instruments using "fscanf" and "fprintf":
Error using matlabshared.transportlib.internal.compatibility.LegacyASCIIMixin/fprintf (line 140)
Error writing String.
Error writing data to the transport.
Adaptor command ‘write’ failed with status code: -550.
Error using matlabshared.transportlib.internal.compatibility.LegacyASCIIMixin/fscanf (line 305)
Failed to read data from the instrument due to a driver error.
These errors occur seemingly at random, and a similar error occurs when using the function "visa" instead of "visadev":
Error using icinterface/fprintf (line 158)
VISA: The IO connection for the session has been lost
Why do these errors occur and how can I prevent them?I am connecting to my Windows 11 based Keysight oscilloscope and source via "visadev." I intermittently receive the following two errors when reading and writing to the instruments using "fscanf" and "fprintf":
Error using matlabshared.transportlib.internal.compatibility.LegacyASCIIMixin/fprintf (line 140)
Error writing String.
Error writing data to the transport.
Adaptor command ‘write’ failed with status code: -550.
Error using matlabshared.transportlib.internal.compatibility.LegacyASCIIMixin/fscanf (line 305)
Failed to read data from the instrument due to a driver error.
These errors occur seemingly at random, and a similar error occurs when using the function "visa" instead of "visadev":
Error using icinterface/fprintf (line 158)
VISA: The IO connection for the session has been lost
Why do these errors occur and how can I prevent them? I am connecting to my Windows 11 based Keysight oscilloscope and source via "visadev." I intermittently receive the following two errors when reading and writing to the instruments using "fscanf" and "fprintf":
Error using matlabshared.transportlib.internal.compatibility.LegacyASCIIMixin/fprintf (line 140)
Error writing String.
Error writing data to the transport.
Adaptor command ‘write’ failed with status code: -550.
Error using matlabshared.transportlib.internal.compatibility.LegacyASCIIMixin/fscanf (line 305)
Failed to read data from the instrument due to a driver error.
These errors occur seemingly at random, and a similar error occurs when using the function "visa" instead of "visadev":
Error using icinterface/fprintf (line 158)
VISA: The IO connection for the session has been lost
Why do these errors occur and how can I prevent them? fprintf, fscanf, instrumentcontroltoolbox, write, read MATLAB Answers — New Questions









