Category: Matlab
Category Archives: Matlab
why exportgraphics fails to print the legend when the content type is vector and the legend is latex interpreted?
when exporting a fig as a vector, e.g. eps or pdf, if the legend is latex interpreted, the exported graphics do not show the legend. Below a snippet of my code:
% Figure
if showFig
f = figure(‘Color’,’w’);
else
f = figure(‘Visible’,’off’,’Color’,’w’);
end
hold on; grid on; box on; set(gca,’YScale’,’log’);
cols = lines(9);
% Plot ML refined (solid) and CRB/PEB (dashed, black markers)
% Case A
p1 = semilogy(x, RMSE_A, ‘-o’, ‘Color’, cols(1,:), ‘LineWidth’, 1.8, ‘MarkerSize’, 6);
p2 = semilogy(x, PEB_A, ‘–o’, ‘Color’, [0 0 0], ‘LineWidth’, 1.3, ‘MarkerSize’, 5);
% Case B
p3 = semilogy(x, RMSE_B, ‘-s’, ‘Color’, cols(2,:), ‘LineWidth’, 1.8, ‘MarkerSize’, 6);
p4 = semilogy(x, PEB_B, ‘–s’, ‘Color’, [0 0 0], ‘LineWidth’, 1.3, ‘MarkerSize’, 5);
% Case C
p5 = semilogy(x, RMSE_C, ‘-^’, ‘Color’, cols(3,:), ‘LineWidth’, 1.8, ‘MarkerSize’, 6);
p6 = semilogy(x, PEB_C, ‘–^’, ‘Color’, [0 0 0], ‘LineWidth’, 1.3, ‘MarkerSize’, 5);
semilogy(R.values, 20*ones(size(R.values)),’:r’,’LineWidth’,1.8);
xlim([min(x) max(x)])
legend([p1 p2 p3 p4 p5 p6], …
{‘ML RMSE_A’,’PEB_A’,’ML RMSE_B’,’PEB_B’,’ML RMSE_C’,’PEB_C’}, …
‘Location’,’best’,’Interpreter’,’latex’);
xlabel(xlab, ‘Interpreter’,’latex’);
ylabel(‘RMSE / PEB [mm]’, ‘Interpreter’,’latex’);
title(run_title, ‘Interpreter’,’none’);
set(gca,’TickLabelInterpreter’,’latex’,’FontSize’,18,’LineWidth’,1.2);
% EXPORT FIG
drawnow; % ensure legend is drawn
set(f, ‘Renderer’, ‘painters’); % force vector renderer
set(f, ‘PaperPositionMode’,’auto’); % match figure size
[~, base, ~] = fileparts(mat_path);
out_path = fullfile(files(i).folder, sprintf(‘%s_PEB_ML.%s’, base, fmt));
switch lower(fmt)
case ‘eps’
saveas(f,out_path,’epsc’)
case ‘pdf’
exportgraphics(gca, [out_path, ‘.pdf’], ‘ContentType’,’vector’)
case ‘png’
print(f, out_path, ‘-dpng’,’-r300′);
otherwise
warning(‘Unknown fmt: %s. Skipping save.’, fmt);
end
endwhen exporting a fig as a vector, e.g. eps or pdf, if the legend is latex interpreted, the exported graphics do not show the legend. Below a snippet of my code:
% Figure
if showFig
f = figure(‘Color’,’w’);
else
f = figure(‘Visible’,’off’,’Color’,’w’);
end
hold on; grid on; box on; set(gca,’YScale’,’log’);
cols = lines(9);
% Plot ML refined (solid) and CRB/PEB (dashed, black markers)
% Case A
p1 = semilogy(x, RMSE_A, ‘-o’, ‘Color’, cols(1,:), ‘LineWidth’, 1.8, ‘MarkerSize’, 6);
p2 = semilogy(x, PEB_A, ‘–o’, ‘Color’, [0 0 0], ‘LineWidth’, 1.3, ‘MarkerSize’, 5);
% Case B
p3 = semilogy(x, RMSE_B, ‘-s’, ‘Color’, cols(2,:), ‘LineWidth’, 1.8, ‘MarkerSize’, 6);
p4 = semilogy(x, PEB_B, ‘–s’, ‘Color’, [0 0 0], ‘LineWidth’, 1.3, ‘MarkerSize’, 5);
% Case C
p5 = semilogy(x, RMSE_C, ‘-^’, ‘Color’, cols(3,:), ‘LineWidth’, 1.8, ‘MarkerSize’, 6);
p6 = semilogy(x, PEB_C, ‘–^’, ‘Color’, [0 0 0], ‘LineWidth’, 1.3, ‘MarkerSize’, 5);
semilogy(R.values, 20*ones(size(R.values)),’:r’,’LineWidth’,1.8);
xlim([min(x) max(x)])
legend([p1 p2 p3 p4 p5 p6], …
{‘ML RMSE_A’,’PEB_A’,’ML RMSE_B’,’PEB_B’,’ML RMSE_C’,’PEB_C’}, …
‘Location’,’best’,’Interpreter’,’latex’);
xlabel(xlab, ‘Interpreter’,’latex’);
ylabel(‘RMSE / PEB [mm]’, ‘Interpreter’,’latex’);
title(run_title, ‘Interpreter’,’none’);
set(gca,’TickLabelInterpreter’,’latex’,’FontSize’,18,’LineWidth’,1.2);
% EXPORT FIG
drawnow; % ensure legend is drawn
set(f, ‘Renderer’, ‘painters’); % force vector renderer
set(f, ‘PaperPositionMode’,’auto’); % match figure size
[~, base, ~] = fileparts(mat_path);
out_path = fullfile(files(i).folder, sprintf(‘%s_PEB_ML.%s’, base, fmt));
switch lower(fmt)
case ‘eps’
saveas(f,out_path,’epsc’)
case ‘pdf’
exportgraphics(gca, [out_path, ‘.pdf’], ‘ContentType’,’vector’)
case ‘png’
print(f, out_path, ‘-dpng’,’-r300′);
otherwise
warning(‘Unknown fmt: %s. Skipping save.’, fmt);
end
end when exporting a fig as a vector, e.g. eps or pdf, if the legend is latex interpreted, the exported graphics do not show the legend. Below a snippet of my code:
% Figure
if showFig
f = figure(‘Color’,’w’);
else
f = figure(‘Visible’,’off’,’Color’,’w’);
end
hold on; grid on; box on; set(gca,’YScale’,’log’);
cols = lines(9);
% Plot ML refined (solid) and CRB/PEB (dashed, black markers)
% Case A
p1 = semilogy(x, RMSE_A, ‘-o’, ‘Color’, cols(1,:), ‘LineWidth’, 1.8, ‘MarkerSize’, 6);
p2 = semilogy(x, PEB_A, ‘–o’, ‘Color’, [0 0 0], ‘LineWidth’, 1.3, ‘MarkerSize’, 5);
% Case B
p3 = semilogy(x, RMSE_B, ‘-s’, ‘Color’, cols(2,:), ‘LineWidth’, 1.8, ‘MarkerSize’, 6);
p4 = semilogy(x, PEB_B, ‘–s’, ‘Color’, [0 0 0], ‘LineWidth’, 1.3, ‘MarkerSize’, 5);
% Case C
p5 = semilogy(x, RMSE_C, ‘-^’, ‘Color’, cols(3,:), ‘LineWidth’, 1.8, ‘MarkerSize’, 6);
p6 = semilogy(x, PEB_C, ‘–^’, ‘Color’, [0 0 0], ‘LineWidth’, 1.3, ‘MarkerSize’, 5);
semilogy(R.values, 20*ones(size(R.values)),’:r’,’LineWidth’,1.8);
xlim([min(x) max(x)])
legend([p1 p2 p3 p4 p5 p6], …
{‘ML RMSE_A’,’PEB_A’,’ML RMSE_B’,’PEB_B’,’ML RMSE_C’,’PEB_C’}, …
‘Location’,’best’,’Interpreter’,’latex’);
xlabel(xlab, ‘Interpreter’,’latex’);
ylabel(‘RMSE / PEB [mm]’, ‘Interpreter’,’latex’);
title(run_title, ‘Interpreter’,’none’);
set(gca,’TickLabelInterpreter’,’latex’,’FontSize’,18,’LineWidth’,1.2);
% EXPORT FIG
drawnow; % ensure legend is drawn
set(f, ‘Renderer’, ‘painters’); % force vector renderer
set(f, ‘PaperPositionMode’,’auto’); % match figure size
[~, base, ~] = fileparts(mat_path);
out_path = fullfile(files(i).folder, sprintf(‘%s_PEB_ML.%s’, base, fmt));
switch lower(fmt)
case ‘eps’
saveas(f,out_path,’epsc’)
case ‘pdf’
exportgraphics(gca, [out_path, ‘.pdf’], ‘ContentType’,’vector’)
case ‘png’
print(f, out_path, ‘-dpng’,’-r300′);
otherwise
warning(‘Unknown fmt: %s. Skipping save.’, fmt);
end
end plot, exportgraphics MATLAB Answers — New Questions
I have a code but am unable to use if conditions with matrix value
My code required a condition for avoiding if 0 value read from text and continue to verify the next valueMy code required a condition for avoiding if 0 value read from text and continue to verify the next value My code required a condition for avoiding if 0 value read from text and continue to verify the next value if statement, continue MATLAB Answers — New Questions
Supressing Live Script plotting figure inline
I am plotting a figure from a Live Script using the
set(gcf, ‘Visible’, ‘on’);
option to make it appear in a separate, external window.
However, a copy of the figure still appears inline the Live Script and I could not find a way to avoid it.
The figure should only appear externally (i.e. in a separate window, which it already does), and not get created inline too.I am plotting a figure from a Live Script using the
set(gcf, ‘Visible’, ‘on’);
option to make it appear in a separate, external window.
However, a copy of the figure still appears inline the Live Script and I could not find a way to avoid it.
The figure should only appear externally (i.e. in a separate window, which it already does), and not get created inline too. I am plotting a figure from a Live Script using the
set(gcf, ‘Visible’, ‘on’);
option to make it appear in a separate, external window.
However, a copy of the figure still appears inline the Live Script and I could not find a way to avoid it.
The figure should only appear externally (i.e. in a separate window, which it already does), and not get created inline too. live script, figure, plot, window MATLAB Answers — New Questions
tf2sos input argument
I have a question about the input argument to the method tf2sos.
The documentation says it takes the coefficients as vectors of the transfer function
.
I suspect that what is actually meant is that it takes as vectors of the transfer function
.
I have tried the following code, but I can not make sense of it.
clear all;
close all;
ts = 1/10000;
z = tf(‘z’, ts);
b0 = 1;
b1 = 2;
b2 = 3;
a0 = 1;
a1 = -2;
a2 = 5;
H = tf([b2, b1, b0], [a2, a1, a0], ts);
Hi = (b0 + b1*z^-1 + b2*z^-2)/(a0 + a1*z^-1 + a2*z^-2);
[sos_H,g_H] = tf2sos(H.Numerator{1}, H.Denominator{1});
[sos_Hi,g_Hi] = tf2sos(Hi.Numerator{1}, Hi.Denominator{1});
K_H = g_H*(sos_H(1,1) + sos_H(1,2)*z^-1 + sos_H(1,3)*z^-2)/(sos_H(1,4) + sos_H(1,5)*z^-1 + sos_H(1,6)*z^-2);
K_Hi = g_Hi*(sos_Hi(1,1) + sos_Hi(1,2)*z^-1 + sos_Hi(1,3)*z^-2)/(sos_Hi(1,4) + sos_Hi(1,5)*z^-1 + sos_Hi(1,6)*z^-2);
figure()
hold on
step(H);
step(K_H, ‘–‘);
legend();
grid();
figure()
hold on;
step(Hi);
step(K_Hi, ‘–‘);
legend();
grid();
What am I doing wrong?I have a question about the input argument to the method tf2sos.
The documentation says it takes the coefficients as vectors of the transfer function
.
I suspect that what is actually meant is that it takes as vectors of the transfer function
.
I have tried the following code, but I can not make sense of it.
clear all;
close all;
ts = 1/10000;
z = tf(‘z’, ts);
b0 = 1;
b1 = 2;
b2 = 3;
a0 = 1;
a1 = -2;
a2 = 5;
H = tf([b2, b1, b0], [a2, a1, a0], ts);
Hi = (b0 + b1*z^-1 + b2*z^-2)/(a0 + a1*z^-1 + a2*z^-2);
[sos_H,g_H] = tf2sos(H.Numerator{1}, H.Denominator{1});
[sos_Hi,g_Hi] = tf2sos(Hi.Numerator{1}, Hi.Denominator{1});
K_H = g_H*(sos_H(1,1) + sos_H(1,2)*z^-1 + sos_H(1,3)*z^-2)/(sos_H(1,4) + sos_H(1,5)*z^-1 + sos_H(1,6)*z^-2);
K_Hi = g_Hi*(sos_Hi(1,1) + sos_Hi(1,2)*z^-1 + sos_Hi(1,3)*z^-2)/(sos_Hi(1,4) + sos_Hi(1,5)*z^-1 + sos_Hi(1,6)*z^-2);
figure()
hold on
step(H);
step(K_H, ‘–‘);
legend();
grid();
figure()
hold on;
step(Hi);
step(K_Hi, ‘–‘);
legend();
grid();
What am I doing wrong? I have a question about the input argument to the method tf2sos.
The documentation says it takes the coefficients as vectors of the transfer function
.
I suspect that what is actually meant is that it takes as vectors of the transfer function
.
I have tried the following code, but I can not make sense of it.
clear all;
close all;
ts = 1/10000;
z = tf(‘z’, ts);
b0 = 1;
b1 = 2;
b2 = 3;
a0 = 1;
a1 = -2;
a2 = 5;
H = tf([b2, b1, b0], [a2, a1, a0], ts);
Hi = (b0 + b1*z^-1 + b2*z^-2)/(a0 + a1*z^-1 + a2*z^-2);
[sos_H,g_H] = tf2sos(H.Numerator{1}, H.Denominator{1});
[sos_Hi,g_Hi] = tf2sos(Hi.Numerator{1}, Hi.Denominator{1});
K_H = g_H*(sos_H(1,1) + sos_H(1,2)*z^-1 + sos_H(1,3)*z^-2)/(sos_H(1,4) + sos_H(1,5)*z^-1 + sos_H(1,6)*z^-2);
K_Hi = g_Hi*(sos_Hi(1,1) + sos_Hi(1,2)*z^-1 + sos_Hi(1,3)*z^-2)/(sos_Hi(1,4) + sos_Hi(1,5)*z^-1 + sos_Hi(1,6)*z^-2);
figure()
hold on
step(H);
step(K_H, ‘–‘);
legend();
grid();
figure()
hold on;
step(Hi);
step(K_Hi, ‘–‘);
legend();
grid();
What am I doing wrong? tf2sos, tf, second order sections MATLAB Answers — New Questions
Help needed with simulink onramp Discrete systems
This is task 4 in Discrete systems and I have already enabled the scope on the legend, and still it’s showing legend not enabled. It’s the same every time I try and I have attempted this twice already. What is wrong?
It is the same in a few other tasks that require legend to be enabled as well. I am unable to submit them even if the legend is clearly enabled.This is task 4 in Discrete systems and I have already enabled the scope on the legend, and still it’s showing legend not enabled. It’s the same every time I try and I have attempted this twice already. What is wrong?
It is the same in a few other tasks that require legend to be enabled as well. I am unable to submit them even if the legend is clearly enabled. This is task 4 in Discrete systems and I have already enabled the scope on the legend, and still it’s showing legend not enabled. It’s the same every time I try and I have attempted this twice already. What is wrong?
It is the same in a few other tasks that require legend to be enabled as well. I am unable to submit them even if the legend is clearly enabled. graph, scope, simulink MATLAB Answers — New Questions
A more efficient way to do this calculation
Hi all,
I am creating a function that allows me to obtain certain data of Steel Members.
I have created limits that give an interval over which to select a particular member.
Here is my code:
function [HD_cols] = members(Ic);
HD400_1299 = [755000/100^4; 1655/100^2; 1299];
HD400_1202 = [664000/100^4; 1530/100^2; 1202];
HD400_1086 = [596000/100^4; 1386/100^2; 1086];
HD400_990 = [519000/100^4; 1262/100^2; 990];
HD400_900 = [450000/100^4; 1149/100^2; 900];
HD400_818 = [392000/100^4; 1043/100^2; 818];
HD400_744 = [342000/100^4; 948/100^2; 744];
HD400_677 = [300000/100^4; 863/100^2; 677];
HD400_634 = [274000/100^4; 808/100^2; 634];
HD400_592 = [250000/100^4; 755/100^2; 592];
HD400_551 = [226000/100^4; 701/100^2; 551];
HD400_509 = [204000/100^4; 649/100^2; 509];
HD400_463 = [180000/100^4; 590/100^2; 463];
HD400_421 = [160000/100^4; 537/100^2; 421];
T = table(HD400_1299,HD400_1202,HD400_1086,HD400_990,HD400_900,HD400_818,HD400_744,HD400_677,HD400_634,HD400_592,HD400_551,HD400_509,HD400_463,HD400_421);
for i = 1:length(Tx)-1
Limits(i) = (Tx(1,i)+Tx(1,i+1))/2;
end
if Ic > Limits(1)
Ic = HD400_1299
elseif Ic > Limits(2)
Ic = HD400_1202
elseif Ic > Limits(3)
Ic = HD400_1086
elseif Ic > Limits(4)
Ic = HD400_990
elseif Ic > Limits(5)
Ic = HD400_900
elseif Ic > Limits(6)
Ic = HD400_818
elseif Ic > Limits(7)
Ic = HD400_744
elseif Ic > Limits(8)
Ic = HD400_677
elseif Ic > Limits(9)
Ic = HD400_634
elseif Ic > Limits(10)
Ic = HD400_592
elseif Ic > Limits(11)
Ic = HD400_551
elseif Ic > Limits(12)
Ic = HD400_509
elseif Ic > Limits(13)
Ic = HD400_463
elseif Ic > Limits(14)
Ic = HD400_421
end
end
My request is, can somone show me how I can simplify and make more efficient my if statements? Perhaps I need to use a loop? I want to add more members to more script and typing like I have above is tedious and not very efficient. So, I’m hoping someone can help?
Many thanks,
ScottHi all,
I am creating a function that allows me to obtain certain data of Steel Members.
I have created limits that give an interval over which to select a particular member.
Here is my code:
function [HD_cols] = members(Ic);
HD400_1299 = [755000/100^4; 1655/100^2; 1299];
HD400_1202 = [664000/100^4; 1530/100^2; 1202];
HD400_1086 = [596000/100^4; 1386/100^2; 1086];
HD400_990 = [519000/100^4; 1262/100^2; 990];
HD400_900 = [450000/100^4; 1149/100^2; 900];
HD400_818 = [392000/100^4; 1043/100^2; 818];
HD400_744 = [342000/100^4; 948/100^2; 744];
HD400_677 = [300000/100^4; 863/100^2; 677];
HD400_634 = [274000/100^4; 808/100^2; 634];
HD400_592 = [250000/100^4; 755/100^2; 592];
HD400_551 = [226000/100^4; 701/100^2; 551];
HD400_509 = [204000/100^4; 649/100^2; 509];
HD400_463 = [180000/100^4; 590/100^2; 463];
HD400_421 = [160000/100^4; 537/100^2; 421];
T = table(HD400_1299,HD400_1202,HD400_1086,HD400_990,HD400_900,HD400_818,HD400_744,HD400_677,HD400_634,HD400_592,HD400_551,HD400_509,HD400_463,HD400_421);
for i = 1:length(Tx)-1
Limits(i) = (Tx(1,i)+Tx(1,i+1))/2;
end
if Ic > Limits(1)
Ic = HD400_1299
elseif Ic > Limits(2)
Ic = HD400_1202
elseif Ic > Limits(3)
Ic = HD400_1086
elseif Ic > Limits(4)
Ic = HD400_990
elseif Ic > Limits(5)
Ic = HD400_900
elseif Ic > Limits(6)
Ic = HD400_818
elseif Ic > Limits(7)
Ic = HD400_744
elseif Ic > Limits(8)
Ic = HD400_677
elseif Ic > Limits(9)
Ic = HD400_634
elseif Ic > Limits(10)
Ic = HD400_592
elseif Ic > Limits(11)
Ic = HD400_551
elseif Ic > Limits(12)
Ic = HD400_509
elseif Ic > Limits(13)
Ic = HD400_463
elseif Ic > Limits(14)
Ic = HD400_421
end
end
My request is, can somone show me how I can simplify and make more efficient my if statements? Perhaps I need to use a loop? I want to add more members to more script and typing like I have above is tedious and not very efficient. So, I’m hoping someone can help?
Many thanks,
Scott Hi all,
I am creating a function that allows me to obtain certain data of Steel Members.
I have created limits that give an interval over which to select a particular member.
Here is my code:
function [HD_cols] = members(Ic);
HD400_1299 = [755000/100^4; 1655/100^2; 1299];
HD400_1202 = [664000/100^4; 1530/100^2; 1202];
HD400_1086 = [596000/100^4; 1386/100^2; 1086];
HD400_990 = [519000/100^4; 1262/100^2; 990];
HD400_900 = [450000/100^4; 1149/100^2; 900];
HD400_818 = [392000/100^4; 1043/100^2; 818];
HD400_744 = [342000/100^4; 948/100^2; 744];
HD400_677 = [300000/100^4; 863/100^2; 677];
HD400_634 = [274000/100^4; 808/100^2; 634];
HD400_592 = [250000/100^4; 755/100^2; 592];
HD400_551 = [226000/100^4; 701/100^2; 551];
HD400_509 = [204000/100^4; 649/100^2; 509];
HD400_463 = [180000/100^4; 590/100^2; 463];
HD400_421 = [160000/100^4; 537/100^2; 421];
T = table(HD400_1299,HD400_1202,HD400_1086,HD400_990,HD400_900,HD400_818,HD400_744,HD400_677,HD400_634,HD400_592,HD400_551,HD400_509,HD400_463,HD400_421);
for i = 1:length(Tx)-1
Limits(i) = (Tx(1,i)+Tx(1,i+1))/2;
end
if Ic > Limits(1)
Ic = HD400_1299
elseif Ic > Limits(2)
Ic = HD400_1202
elseif Ic > Limits(3)
Ic = HD400_1086
elseif Ic > Limits(4)
Ic = HD400_990
elseif Ic > Limits(5)
Ic = HD400_900
elseif Ic > Limits(6)
Ic = HD400_818
elseif Ic > Limits(7)
Ic = HD400_744
elseif Ic > Limits(8)
Ic = HD400_677
elseif Ic > Limits(9)
Ic = HD400_634
elseif Ic > Limits(10)
Ic = HD400_592
elseif Ic > Limits(11)
Ic = HD400_551
elseif Ic > Limits(12)
Ic = HD400_509
elseif Ic > Limits(13)
Ic = HD400_463
elseif Ic > Limits(14)
Ic = HD400_421
end
end
My request is, can somone show me how I can simplify and make more efficient my if statements? Perhaps I need to use a loop? I want to add more members to more script and typing like I have above is tedious and not very efficient. So, I’m hoping someone can help?
Many thanks,
Scott for, loop, functions, if statement MATLAB Answers — New Questions
Hi all, I want to be a able to paste data in any column all at once not cell by in MATLAB APP table.
T_Fixed = table(StartDates_Fixed,EndDates_Fixed,PaymentDates_Fixed,Notional,fixedrate);
app.Details_Fixed.Data = T_Fixed;
app.Details_Fixed.ColumnEditable =true(1,5);T_Fixed = table(StartDates_Fixed,EndDates_Fixed,PaymentDates_Fixed,Notional,fixedrate);
app.Details_Fixed.Data = T_Fixed;
app.Details_Fixed.ColumnEditable =true(1,5); T_Fixed = table(StartDates_Fixed,EndDates_Fixed,PaymentDates_Fixed,Notional,fixedrate);
app.Details_Fixed.Data = T_Fixed;
app.Details_Fixed.ColumnEditable =true(1,5); app designer, matlab MATLAB Answers — New Questions
need real data for Electrical viechle
Hello dear
I wiuld like to know if nay resarch center or universities can help me to get real data for Electrical viechle
Best regardsHello dear
I wiuld like to know if nay resarch center or universities can help me to get real data for Electrical viechle
Best regards Hello dear
I wiuld like to know if nay resarch center or universities can help me to get real data for Electrical viechle
Best regards need real data for electrical viechle, electrical viechle MATLAB Answers — New Questions
Security error using fred/fetch
Hi,
I recently updated the Mac software to Sequoia, and started to receive the following error for a code that has always worked before:
Error using fred/fetch
Unable to retrieve data. Verify valid security request.
Do you know how to fix this? I have updated the Matlab version to the latest, and the error still persists.
Thanks!Hi,
I recently updated the Mac software to Sequoia, and started to receive the following error for a code that has always worked before:
Error using fred/fetch
Unable to retrieve data. Verify valid security request.
Do you know how to fix this? I have updated the Matlab version to the latest, and the error still persists.
Thanks! Hi,
I recently updated the Mac software to Sequoia, and started to receive the following error for a code that has always worked before:
Error using fred/fetch
Unable to retrieve data. Verify valid security request.
Do you know how to fix this? I have updated the Matlab version to the latest, and the error still persists.
Thanks! fred, fetch MATLAB Answers — New Questions
Documentation on creating a box label datastore for bounding box label data with Sublabels?
Hello, I’m having trouble figuring how to train a fasterRCNN network using a labeled dataset I hand-labeled in Matlab with sublabels. I know how to create a boxLabelDatastore for just labeling 1 object but I can’t figure out how to do this when I have sublabels. The error I get when I try to apply my old code for one object with no sublabels is as follows…
"Error using boxLabelDatastore
Invalid data in column 1 of input table 1.
Caused by:
Error using boxLabelDatastore>iAssertValidBBoxFormat
The size of bounding box data must be M-by-4, M-by-5, or M-by-9, where M is the number of boxes in each table element. The column in the training data table that contains thebounding boxes must be a cell array."
also this function does not work either…
[imds,blds] = objectDetectorTrainingData(gTruth)
Warning: groundTruth object/s contain attribute or sublabel data. These are not included in the output table.
> In objectDetectorTrainingData>populateTrainingTable (line 330)
In objectDetectorTrainingData (line 165)
I also have not been able to find any examples of going from a gTruth datastore to actually training a network in the examplesHello, I’m having trouble figuring how to train a fasterRCNN network using a labeled dataset I hand-labeled in Matlab with sublabels. I know how to create a boxLabelDatastore for just labeling 1 object but I can’t figure out how to do this when I have sublabels. The error I get when I try to apply my old code for one object with no sublabels is as follows…
"Error using boxLabelDatastore
Invalid data in column 1 of input table 1.
Caused by:
Error using boxLabelDatastore>iAssertValidBBoxFormat
The size of bounding box data must be M-by-4, M-by-5, or M-by-9, where M is the number of boxes in each table element. The column in the training data table that contains thebounding boxes must be a cell array."
also this function does not work either…
[imds,blds] = objectDetectorTrainingData(gTruth)
Warning: groundTruth object/s contain attribute or sublabel data. These are not included in the output table.
> In objectDetectorTrainingData>populateTrainingTable (line 330)
In objectDetectorTrainingData (line 165)
I also have not been able to find any examples of going from a gTruth datastore to actually training a network in the examples Hello, I’m having trouble figuring how to train a fasterRCNN network using a labeled dataset I hand-labeled in Matlab with sublabels. I know how to create a boxLabelDatastore for just labeling 1 object but I can’t figure out how to do this when I have sublabels. The error I get when I try to apply my old code for one object with no sublabels is as follows…
"Error using boxLabelDatastore
Invalid data in column 1 of input table 1.
Caused by:
Error using boxLabelDatastore>iAssertValidBBoxFormat
The size of bounding box data must be M-by-4, M-by-5, or M-by-9, where M is the number of boxes in each table element. The column in the training data table that contains thebounding boxes must be a cell array."
also this function does not work either…
[imds,blds] = objectDetectorTrainingData(gTruth)
Warning: groundTruth object/s contain attribute or sublabel data. These are not included in the output table.
> In objectDetectorTrainingData>populateTrainingTable (line 330)
In objectDetectorTrainingData (line 165)
I also have not been able to find any examples of going from a gTruth datastore to actually training a network in the examples sublabels, fasterrcnn, object detection, deep learning MATLAB Answers — New Questions
Do you have a HECVAT & VPAT for the MATLAB software?
Do you have a HECVAT & VPAT for the MATLAB software?Do you have a HECVAT & VPAT for the MATLAB software? Do you have a HECVAT & VPAT for the MATLAB software? hecvat, vpat MATLAB Answers — New Questions
Neural network classification improvments
hi all,
I have trained a neural network using fitcnet, the data is a simple classification of hole numbering. the data is as per the simplified attached picture. but essentially the center of the hole xy point, the angle and distance relative to the center of the whole blade, the whole blade major axis and finally the hole number a value from 1:319.
the problem i have found is two-fold.
i think it may be ‘over-fitted’ it works well on the synthetic data but performs worse on real data
2. it rountinly will identify multilple holes as the same number e.g there would be 4 hole number 3’s now in the real data sometimes a single hole can split into a pair of much smaller holes they stay rougly within bounds of the original hole.
The data into the training was a single row of info for one hole listing the above info including its class effectivly treating each time i then ask it to predict the classification of a new hole being a ‘clean-sheet’ with no knowledge of already predicted holes.
Does anyone have any suggestions for possible improvments?
many thanks timhi all,
I have trained a neural network using fitcnet, the data is a simple classification of hole numbering. the data is as per the simplified attached picture. but essentially the center of the hole xy point, the angle and distance relative to the center of the whole blade, the whole blade major axis and finally the hole number a value from 1:319.
the problem i have found is two-fold.
i think it may be ‘over-fitted’ it works well on the synthetic data but performs worse on real data
2. it rountinly will identify multilple holes as the same number e.g there would be 4 hole number 3’s now in the real data sometimes a single hole can split into a pair of much smaller holes they stay rougly within bounds of the original hole.
The data into the training was a single row of info for one hole listing the above info including its class effectivly treating each time i then ask it to predict the classification of a new hole being a ‘clean-sheet’ with no knowledge of already predicted holes.
Does anyone have any suggestions for possible improvments?
many thanks tim hi all,
I have trained a neural network using fitcnet, the data is a simple classification of hole numbering. the data is as per the simplified attached picture. but essentially the center of the hole xy point, the angle and distance relative to the center of the whole blade, the whole blade major axis and finally the hole number a value from 1:319.
the problem i have found is two-fold.
i think it may be ‘over-fitted’ it works well on the synthetic data but performs worse on real data
2. it rountinly will identify multilple holes as the same number e.g there would be 4 hole number 3’s now in the real data sometimes a single hole can split into a pair of much smaller holes they stay rougly within bounds of the original hole.
The data into the training was a single row of info for one hole listing the above info including its class effectivly treating each time i then ask it to predict the classification of a new hole being a ‘clean-sheet’ with no knowledge of already predicted holes.
Does anyone have any suggestions for possible improvments?
many thanks tim fitcnet, neural network MATLAB Answers — New Questions
Sort Internal Variables in FMU
Hi,
I am exporting a Simulink model with some pre-defined internal variables as a FMU. There are properly exported. However, the order is not respected; they seem to be randomly sorted inside the FMU object.
Is there any way I could solve this issue?
Thank you very much in advance.
Best regards,
Víctor Sánchez SuárezHi,
I am exporting a Simulink model with some pre-defined internal variables as a FMU. There are properly exported. However, the order is not respected; they seem to be randomly sorted inside the FMU object.
Is there any way I could solve this issue?
Thank you very much in advance.
Best regards,
Víctor Sánchez Suárez Hi,
I am exporting a Simulink model with some pre-defined internal variables as a FMU. There are properly exported. However, the order is not respected; they seem to be randomly sorted inside the FMU object.
Is there any way I could solve this issue?
Thank you very much in advance.
Best regards,
Víctor Sánchez Suárez fmu, simulink, internal variables, export MATLAB Answers — New Questions
How do I migrate my command history data from older releases to MATLAB R2025a?
How do I migrate my command history data from older releases to MATLAB R2025a?How do I migrate my command history data from older releases to MATLAB R2025a? How do I migrate my command history data from older releases to MATLAB R2025a? command_history, command_history_migration, new_desktop MATLAB Answers — New Questions
How to write single Script for all profiles ?
The input in my case is the measurement data from a sensor doing spiral scanning. So I have 3D point data (x, y, z) of the surface for different geometries like hemisphere, plane, sphere, and cylinder. The script should preprocess this data (filtering, centering, vertex search), fit the right model (sphere, plane, cylinder, or freeform), and then output the fitted parameters along with residuals. The outcomes I want are both numerical results (fit parameters and errors) and visualizations in 2D cross-sections and 3D surface plots.The input in my case is the measurement data from a sensor doing spiral scanning. So I have 3D point data (x, y, z) of the surface for different geometries like hemisphere, plane, sphere, and cylinder. The script should preprocess this data (filtering, centering, vertex search), fit the right model (sphere, plane, cylinder, or freeform), and then output the fitted parameters along with residuals. The outcomes I want are both numerical results (fit parameters and errors) and visualizations in 2D cross-sections and 3D surface plots. The input in my case is the measurement data from a sensor doing spiral scanning. So I have 3D point data (x, y, z) of the surface for different geometries like hemisphere, plane, sphere, and cylinder. The script should preprocess this data (filtering, centering, vertex search), fit the right model (sphere, plane, cylinder, or freeform), and then output the fitted parameters along with residuals. The outcomes I want are both numerical results (fit parameters and errors) and visualizations in 2D cross-sections and 3D surface plots. measurement, sensor, spiral, scan, preprocess, fit, residuals, 2d, 3d, surface MATLAB Answers — New Questions
How can I cross-compile a standalone FMU that I exported from Simulink with Simulink Compiler?
I would like to reuse a standalone FMU generated with Simulink Compiler on another platform. For example, adding Linux binaries when a Simulink model is exported to FMU on Windows platform.I would like to reuse a standalone FMU generated with Simulink Compiler on another platform. For example, adding Linux binaries when a Simulink model is exported to FMU on Windows platform. I would like to reuse a standalone FMU generated with Simulink Compiler on another platform. For example, adding Linux binaries when a Simulink model is exported to FMU on Windows platform. savesourcecodetofmu, cross-compile, codegen MATLAB Answers — New Questions
How can I protect my system from unsafe Model/Block Callbacks
I experiment on thousands of external Simulink models for my research projects. When dealing with them, e.g., performing load_system(<model>) , how can I protect my system from malicious callbacks? Of course I can do a set_param(<model>/<blocks>, <CallBackFcn>, ”) for the model and every block, but only after loading it, though? This means all "LoadFcn" will be executed, up and including a potential rm -rf ~/* or whatever creative malicious code might be hidden somewhere in the model. On open_model(<model>) the "OpenFcn" will be executed similarly.
Is there a sandbox functionality to deal with this attack vector?I experiment on thousands of external Simulink models for my research projects. When dealing with them, e.g., performing load_system(<model>) , how can I protect my system from malicious callbacks? Of course I can do a set_param(<model>/<blocks>, <CallBackFcn>, ”) for the model and every block, but only after loading it, though? This means all "LoadFcn" will be executed, up and including a potential rm -rf ~/* or whatever creative malicious code might be hidden somewhere in the model. On open_model(<model>) the "OpenFcn" will be executed similarly.
Is there a sandbox functionality to deal with this attack vector? I experiment on thousands of external Simulink models for my research projects. When dealing with them, e.g., performing load_system(<model>) , how can I protect my system from malicious callbacks? Of course I can do a set_param(<model>/<blocks>, <CallBackFcn>, ”) for the model and every block, but only after loading it, though? This means all "LoadFcn" will be executed, up and including a potential rm -rf ~/* or whatever creative malicious code might be hidden somewhere in the model. On open_model(<model>) the "OpenFcn" will be executed similarly.
Is there a sandbox functionality to deal with this attack vector? callback, sandbox, trust, safeness MATLAB Answers — New Questions
Unable to read .bin data from Jetson
I am try to run a matched Filter function on jetson, using the ‘exe’ library, but there is no data inside the .bin file that i have generated.
here is the matched filter fucntion
function mf_output = matched_Filter_GPU(rx_signal_noisy, matched_filter, NsampPRI,Npulses) %#codegen
coder.gpu.kernelfun;
rx_signal_noisy1 = (rx_signal_noisy); (rx_signal (1×100000 complex double )
matched_filter1 = (matched_filter); (matched_filter 1×100 complex double)
RX_matrix = reshape(rx_signal_noisy1, NsampPRI, Npulses);
mf_output = conv2(RX_matrix, matched_filter1, ‘same’);
end
here is the wrapper function
function matched_Filter_wrapper(rx_signal_noisy, matched_filter, NsampPRI, Npulses) %#codegen
coder.gpu.kernelfun;
coder.extrinsic(‘fopen’,’fwrite’,’fclose’);
mf_output = matched_Filter_GPU(rx_signal_noisy, matched_filter, NsampPRI, Npulses);
fid = fopen(‘output_new.bin’, ‘w’);
fwrite(fid, [1000 100], ‘int32’);
fwrite(fid, [real(mf_output)], ‘single’)
fclose(fid);
end
here is the MATLAB code
clear
S = load(‘rx_signal_noisy.mat’);
rx_signal_noisy = single(struct2array(S));
S = load(‘MF_coeff.mat’);
MF_coeff = single(struct2array(S));
NsampPRI = int32(1000);
Npulses = int32(100);
hwObj = jetson(‘169.254.172.219′,’hr’,’0000′);
rx_signal_noisy_T = coder.typeof(complex(single(0)), [1 100000], [0 0]);
matched_filter_T = coder.typeof(complex(single(0)), [1 100], [0 0]);
NsampPRI_T = coder.typeof(int32(0), [1 1], [0 0]);
Npulses_T = coder.typeof(int32(0), [1 1], [0 0]);
outfile_T = coder.typeof(‘a’, [1 200], [0 1]);
cfg = coder.gpuConfig(‘exe’);
cfg.Hardware = coder.Hardware(‘NVIDIA Jetson’);
cfg.GenerateReport = false;
cfg.VerificationMode = ‘None’;
cfg.CodeExecutionProfiling = false;
cfg.GenerateExampleMain = ‘GenerateCodeAndCompile’;
cfg.Hardware.BuildDir = ‘~/remoteBuildDir’;
codegen -config cfg matched_Filter_wrapper -args {rx_signal_noisy_T, matched_filter_T, NsampPRI_T, Npulses_T}
system(hwObj, ‘./matched_Filter_wrapper.elf’);
getFile(hwObj, ‘~/remoteBuildDir/MATLAB_ws/R2024a/D/Drive_Data/Radar/Radar/output_new.bin’)
fid = fopen(‘output_new.bin’,’r’);
size1 = fread(fid,2, ‘int32’);
output = fread(fid, prod(NsampPRI), ‘single’);
kindly guide me throigh the process, it will be a great help. thankyou in advanceI am try to run a matched Filter function on jetson, using the ‘exe’ library, but there is no data inside the .bin file that i have generated.
here is the matched filter fucntion
function mf_output = matched_Filter_GPU(rx_signal_noisy, matched_filter, NsampPRI,Npulses) %#codegen
coder.gpu.kernelfun;
rx_signal_noisy1 = (rx_signal_noisy); (rx_signal (1×100000 complex double )
matched_filter1 = (matched_filter); (matched_filter 1×100 complex double)
RX_matrix = reshape(rx_signal_noisy1, NsampPRI, Npulses);
mf_output = conv2(RX_matrix, matched_filter1, ‘same’);
end
here is the wrapper function
function matched_Filter_wrapper(rx_signal_noisy, matched_filter, NsampPRI, Npulses) %#codegen
coder.gpu.kernelfun;
coder.extrinsic(‘fopen’,’fwrite’,’fclose’);
mf_output = matched_Filter_GPU(rx_signal_noisy, matched_filter, NsampPRI, Npulses);
fid = fopen(‘output_new.bin’, ‘w’);
fwrite(fid, [1000 100], ‘int32’);
fwrite(fid, [real(mf_output)], ‘single’)
fclose(fid);
end
here is the MATLAB code
clear
S = load(‘rx_signal_noisy.mat’);
rx_signal_noisy = single(struct2array(S));
S = load(‘MF_coeff.mat’);
MF_coeff = single(struct2array(S));
NsampPRI = int32(1000);
Npulses = int32(100);
hwObj = jetson(‘169.254.172.219′,’hr’,’0000′);
rx_signal_noisy_T = coder.typeof(complex(single(0)), [1 100000], [0 0]);
matched_filter_T = coder.typeof(complex(single(0)), [1 100], [0 0]);
NsampPRI_T = coder.typeof(int32(0), [1 1], [0 0]);
Npulses_T = coder.typeof(int32(0), [1 1], [0 0]);
outfile_T = coder.typeof(‘a’, [1 200], [0 1]);
cfg = coder.gpuConfig(‘exe’);
cfg.Hardware = coder.Hardware(‘NVIDIA Jetson’);
cfg.GenerateReport = false;
cfg.VerificationMode = ‘None’;
cfg.CodeExecutionProfiling = false;
cfg.GenerateExampleMain = ‘GenerateCodeAndCompile’;
cfg.Hardware.BuildDir = ‘~/remoteBuildDir’;
codegen -config cfg matched_Filter_wrapper -args {rx_signal_noisy_T, matched_filter_T, NsampPRI_T, Npulses_T}
system(hwObj, ‘./matched_Filter_wrapper.elf’);
getFile(hwObj, ‘~/remoteBuildDir/MATLAB_ws/R2024a/D/Drive_Data/Radar/Radar/output_new.bin’)
fid = fopen(‘output_new.bin’,’r’);
size1 = fread(fid,2, ‘int32’);
output = fread(fid, prod(NsampPRI), ‘single’);
kindly guide me throigh the process, it will be a great help. thankyou in advance I am try to run a matched Filter function on jetson, using the ‘exe’ library, but there is no data inside the .bin file that i have generated.
here is the matched filter fucntion
function mf_output = matched_Filter_GPU(rx_signal_noisy, matched_filter, NsampPRI,Npulses) %#codegen
coder.gpu.kernelfun;
rx_signal_noisy1 = (rx_signal_noisy); (rx_signal (1×100000 complex double )
matched_filter1 = (matched_filter); (matched_filter 1×100 complex double)
RX_matrix = reshape(rx_signal_noisy1, NsampPRI, Npulses);
mf_output = conv2(RX_matrix, matched_filter1, ‘same’);
end
here is the wrapper function
function matched_Filter_wrapper(rx_signal_noisy, matched_filter, NsampPRI, Npulses) %#codegen
coder.gpu.kernelfun;
coder.extrinsic(‘fopen’,’fwrite’,’fclose’);
mf_output = matched_Filter_GPU(rx_signal_noisy, matched_filter, NsampPRI, Npulses);
fid = fopen(‘output_new.bin’, ‘w’);
fwrite(fid, [1000 100], ‘int32’);
fwrite(fid, [real(mf_output)], ‘single’)
fclose(fid);
end
here is the MATLAB code
clear
S = load(‘rx_signal_noisy.mat’);
rx_signal_noisy = single(struct2array(S));
S = load(‘MF_coeff.mat’);
MF_coeff = single(struct2array(S));
NsampPRI = int32(1000);
Npulses = int32(100);
hwObj = jetson(‘169.254.172.219′,’hr’,’0000′);
rx_signal_noisy_T = coder.typeof(complex(single(0)), [1 100000], [0 0]);
matched_filter_T = coder.typeof(complex(single(0)), [1 100], [0 0]);
NsampPRI_T = coder.typeof(int32(0), [1 1], [0 0]);
Npulses_T = coder.typeof(int32(0), [1 1], [0 0]);
outfile_T = coder.typeof(‘a’, [1 200], [0 1]);
cfg = coder.gpuConfig(‘exe’);
cfg.Hardware = coder.Hardware(‘NVIDIA Jetson’);
cfg.GenerateReport = false;
cfg.VerificationMode = ‘None’;
cfg.CodeExecutionProfiling = false;
cfg.GenerateExampleMain = ‘GenerateCodeAndCompile’;
cfg.Hardware.BuildDir = ‘~/remoteBuildDir’;
codegen -config cfg matched_Filter_wrapper -args {rx_signal_noisy_T, matched_filter_T, NsampPRI_T, Npulses_T}
system(hwObj, ‘./matched_Filter_wrapper.elf’);
getFile(hwObj, ‘~/remoteBuildDir/MATLAB_ws/R2024a/D/Drive_Data/Radar/Radar/output_new.bin’)
fid = fopen(‘output_new.bin’,’r’);
size1 = fread(fid,2, ‘int32’);
output = fread(fid, prod(NsampPRI), ‘single’);
kindly guide me throigh the process, it will be a great help. thankyou in advance nvidia jetson, binary, exe MATLAB Answers — New Questions
Issues in the Structural Design of Injectors
Hi friends!If I know the inlet flow and pressure of the jet pump, as well as the suction port flow and pressure, can I use MATLAB’s jet pump function to obtain the detailed structural dimensions of the jet pump?Hi friends!If I know the inlet flow and pressure of the jet pump, as well as the suction port flow and pressure, can I use MATLAB’s jet pump function to obtain the detailed structural dimensions of the jet pump? Hi friends!If I know the inlet flow and pressure of the jet pump, as well as the suction port flow and pressure, can I use MATLAB’s jet pump function to obtain the detailed structural dimensions of the jet pump? jet pump MATLAB Answers — New Questions
Issues with nlinfit – not fitting second parameter? Fitting a Blackbody curve
Hello all,
I have code to fit a curve to a set of data (a black body curve). I used nlinfit so I could extract errors on the fitted parameters, but I can’t seem to get the second parameter to be considered?
I should end up with a set of 50 plots for the fits, and then a final plot showing luminosity, temp and radius over time. However, the temp over time plot is just displaying the initial value for nlinfit.
Any ideas on what I am doing wrong here?
%errors and fitting of BB function
%constants needed for BB equation
% SI UNITS
c=2.998e8;
h=6.6261e-34;
kb=1.38e-23;
%wavelengths, x data
x = [0.000000212 0.000000231 0.000000291 3.465E-07 3.543E-07 0.000000365 0.000000445 0.000000477 0.000000551 6.231E-07 0.000000658 7.625E-07 0.000000806 9.134E-07 0.00000163];
%flux densities at one epoch (each row is an epoch).
intvaluesallSED = readmatrix("int_values_allSED_3.xlsx");
results = zeros(50,8);
for i = 1:size(intvaluesallSED,1)
flux_den_uncorrected = intvaluesallSED(i,:);
flux_den = flux_den_uncorrected – [3.044257148 2.764380323 1.849636489 1.578043671 1.551640889 1.518279132 1.295492704 1.195475706 0.975440567 0.82279158 0.761751691 0.606214695 0.552059178 0.443122732 0.168971244];
%convert flux den to fv (in SI units)
fv = 3.631e-23.*exp(-0.921034.*flux_den);
%convert fv to f_lambda
f_lambda = fv.*(c./(x.^2));
%for plotting use lambda*f_lambda – y data
y = x.*f_lambda;
%plot figure with data
figure
plot(x, y, ‘o’, ‘MarkerFaceColor’, ‘b’, ‘MarkerSize’, 5);
xlabel(‘Wavelength (m)’);
ylabel(‘lambdaf_lambda’);
%BB function and fit. Here b1 is the aplha multiplication factor and b2 is
%temp. Multiplied by wavelength(xdata) as plotted with lambda*f_lambda
BBfun = @(b,x) (b(1)).*x.*(2.*pi.*h.*(c^2)./(x.^5)).*(1./(exp((h.*c)./(x.*kb.*b(2)))-1));
beta0 = [2.2e-27 ;3e4];
[beta,R,J,CovB,MSE,ErrorModelInfo] = nlinfit(x,y,BBfun,beta0);
%Output values and errors
% b1 is alplha multiplication factor = (R/D)^2, detnoted A. b2 is temp
ci = nlparci(beta,R,"Covar",CovB);
errA = (((ci(1,2)) – (ci(1,1)))/2);
errTemp = ((ci(2,2) – ci(2,1))/2);
A = ((beta(1,1)));
Temp = beta(2,1);
Rad = sqrt(A)*1.85e+24; %convert to radius, distance to transient 1.85e+24
errRad = Rad*sqrt(((0.5*errA)/A)^2 + (4.19e+22/1.85e+24)^2); %error propagation from aplha and distance
%stephan-boltzmann constant
sb = 5.67e-08;
Lum = (4*pi*Rad^2*sb*Temp^4)*1e7; %in erg/s
errLum = Lum*sqrt((2*errRad/Rad)^2 + (4*errTemp/Temp)^2);
results(i,1) = A;
results(i,2) = errA;
results(i,3) = Rad;
results(i,4) = errRad;
results(i,5) = Temp;
results(i,6) = errTemp;
results(i,7) = Lum;
results(i,8) = errLum;
%plot fit
hold on
plot(x,BBfun(beta,x),’-r’);
hold off
end
%final plots
time = [3.4421, 4.2246, 5.695, 6.6946, 7.0809, 7.2812, 8.8125, 9.6112, 10.6128, 11.5382, 11.6742, 13.3953, 14.7236, 15.6233, 16.7919, 17.0436, 18.7829, 19.1707, 20.6369, 21.7721, 22.1614, 22.1619, 23.1565, 23.1571, 23.7631, 24.2266, 25.2168, 26.1579, 26.7577, 27.4169, 29.7512, 31.5264, 33.9284, 35.2449, 37.2385, 38.8981, 39.1618, 40.3597, 41.1686, 42.1524, 44.2117, 45.8706, 46.9335, 47.2638, 48.4002, 50.1866, 52.4438, 55.7044, 60.2141, 69.4632];
figure
t=tiledlayout(3,1,’TileSpacing’,’none’);
nexttile;
errorbar(time, results(:,7), results(:,8), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Luminosity (erg/s)’)
title(‘Luminosity over time’)
set(gca, ‘YScale’, ‘log’)
ytickformat(‘%.1e’)
ylim([6e41 4e45])
nexttile;
errorbar(time, results(:,3), results(:,4), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Radius (m)’)
%title(‘Radius over time’)
ax2 = gca;
ax2.YAxis.Exponent = 0;
ytickformat(‘%.1e’)
ylim([2.5e11 2.5e13])
nexttile;
errorbar(time, results(:,5), results(:,6), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Temperature (K)’)
%title(‘Temperature over time’)
ax3 = gca;
ax3.YAxis.Exponent = 0;
ytickformat(‘%.1e’)
ylim([0 4e4])
The file needed to run the code is attached as well.Hello all,
I have code to fit a curve to a set of data (a black body curve). I used nlinfit so I could extract errors on the fitted parameters, but I can’t seem to get the second parameter to be considered?
I should end up with a set of 50 plots for the fits, and then a final plot showing luminosity, temp and radius over time. However, the temp over time plot is just displaying the initial value for nlinfit.
Any ideas on what I am doing wrong here?
%errors and fitting of BB function
%constants needed for BB equation
% SI UNITS
c=2.998e8;
h=6.6261e-34;
kb=1.38e-23;
%wavelengths, x data
x = [0.000000212 0.000000231 0.000000291 3.465E-07 3.543E-07 0.000000365 0.000000445 0.000000477 0.000000551 6.231E-07 0.000000658 7.625E-07 0.000000806 9.134E-07 0.00000163];
%flux densities at one epoch (each row is an epoch).
intvaluesallSED = readmatrix("int_values_allSED_3.xlsx");
results = zeros(50,8);
for i = 1:size(intvaluesallSED,1)
flux_den_uncorrected = intvaluesallSED(i,:);
flux_den = flux_den_uncorrected – [3.044257148 2.764380323 1.849636489 1.578043671 1.551640889 1.518279132 1.295492704 1.195475706 0.975440567 0.82279158 0.761751691 0.606214695 0.552059178 0.443122732 0.168971244];
%convert flux den to fv (in SI units)
fv = 3.631e-23.*exp(-0.921034.*flux_den);
%convert fv to f_lambda
f_lambda = fv.*(c./(x.^2));
%for plotting use lambda*f_lambda – y data
y = x.*f_lambda;
%plot figure with data
figure
plot(x, y, ‘o’, ‘MarkerFaceColor’, ‘b’, ‘MarkerSize’, 5);
xlabel(‘Wavelength (m)’);
ylabel(‘lambdaf_lambda’);
%BB function and fit. Here b1 is the aplha multiplication factor and b2 is
%temp. Multiplied by wavelength(xdata) as plotted with lambda*f_lambda
BBfun = @(b,x) (b(1)).*x.*(2.*pi.*h.*(c^2)./(x.^5)).*(1./(exp((h.*c)./(x.*kb.*b(2)))-1));
beta0 = [2.2e-27 ;3e4];
[beta,R,J,CovB,MSE,ErrorModelInfo] = nlinfit(x,y,BBfun,beta0);
%Output values and errors
% b1 is alplha multiplication factor = (R/D)^2, detnoted A. b2 is temp
ci = nlparci(beta,R,"Covar",CovB);
errA = (((ci(1,2)) – (ci(1,1)))/2);
errTemp = ((ci(2,2) – ci(2,1))/2);
A = ((beta(1,1)));
Temp = beta(2,1);
Rad = sqrt(A)*1.85e+24; %convert to radius, distance to transient 1.85e+24
errRad = Rad*sqrt(((0.5*errA)/A)^2 + (4.19e+22/1.85e+24)^2); %error propagation from aplha and distance
%stephan-boltzmann constant
sb = 5.67e-08;
Lum = (4*pi*Rad^2*sb*Temp^4)*1e7; %in erg/s
errLum = Lum*sqrt((2*errRad/Rad)^2 + (4*errTemp/Temp)^2);
results(i,1) = A;
results(i,2) = errA;
results(i,3) = Rad;
results(i,4) = errRad;
results(i,5) = Temp;
results(i,6) = errTemp;
results(i,7) = Lum;
results(i,8) = errLum;
%plot fit
hold on
plot(x,BBfun(beta,x),’-r’);
hold off
end
%final plots
time = [3.4421, 4.2246, 5.695, 6.6946, 7.0809, 7.2812, 8.8125, 9.6112, 10.6128, 11.5382, 11.6742, 13.3953, 14.7236, 15.6233, 16.7919, 17.0436, 18.7829, 19.1707, 20.6369, 21.7721, 22.1614, 22.1619, 23.1565, 23.1571, 23.7631, 24.2266, 25.2168, 26.1579, 26.7577, 27.4169, 29.7512, 31.5264, 33.9284, 35.2449, 37.2385, 38.8981, 39.1618, 40.3597, 41.1686, 42.1524, 44.2117, 45.8706, 46.9335, 47.2638, 48.4002, 50.1866, 52.4438, 55.7044, 60.2141, 69.4632];
figure
t=tiledlayout(3,1,’TileSpacing’,’none’);
nexttile;
errorbar(time, results(:,7), results(:,8), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Luminosity (erg/s)’)
title(‘Luminosity over time’)
set(gca, ‘YScale’, ‘log’)
ytickformat(‘%.1e’)
ylim([6e41 4e45])
nexttile;
errorbar(time, results(:,3), results(:,4), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Radius (m)’)
%title(‘Radius over time’)
ax2 = gca;
ax2.YAxis.Exponent = 0;
ytickformat(‘%.1e’)
ylim([2.5e11 2.5e13])
nexttile;
errorbar(time, results(:,5), results(:,6), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Temperature (K)’)
%title(‘Temperature over time’)
ax3 = gca;
ax3.YAxis.Exponent = 0;
ytickformat(‘%.1e’)
ylim([0 4e4])
The file needed to run the code is attached as well. Hello all,
I have code to fit a curve to a set of data (a black body curve). I used nlinfit so I could extract errors on the fitted parameters, but I can’t seem to get the second parameter to be considered?
I should end up with a set of 50 plots for the fits, and then a final plot showing luminosity, temp and radius over time. However, the temp over time plot is just displaying the initial value for nlinfit.
Any ideas on what I am doing wrong here?
%errors and fitting of BB function
%constants needed for BB equation
% SI UNITS
c=2.998e8;
h=6.6261e-34;
kb=1.38e-23;
%wavelengths, x data
x = [0.000000212 0.000000231 0.000000291 3.465E-07 3.543E-07 0.000000365 0.000000445 0.000000477 0.000000551 6.231E-07 0.000000658 7.625E-07 0.000000806 9.134E-07 0.00000163];
%flux densities at one epoch (each row is an epoch).
intvaluesallSED = readmatrix("int_values_allSED_3.xlsx");
results = zeros(50,8);
for i = 1:size(intvaluesallSED,1)
flux_den_uncorrected = intvaluesallSED(i,:);
flux_den = flux_den_uncorrected – [3.044257148 2.764380323 1.849636489 1.578043671 1.551640889 1.518279132 1.295492704 1.195475706 0.975440567 0.82279158 0.761751691 0.606214695 0.552059178 0.443122732 0.168971244];
%convert flux den to fv (in SI units)
fv = 3.631e-23.*exp(-0.921034.*flux_den);
%convert fv to f_lambda
f_lambda = fv.*(c./(x.^2));
%for plotting use lambda*f_lambda – y data
y = x.*f_lambda;
%plot figure with data
figure
plot(x, y, ‘o’, ‘MarkerFaceColor’, ‘b’, ‘MarkerSize’, 5);
xlabel(‘Wavelength (m)’);
ylabel(‘lambdaf_lambda’);
%BB function and fit. Here b1 is the aplha multiplication factor and b2 is
%temp. Multiplied by wavelength(xdata) as plotted with lambda*f_lambda
BBfun = @(b,x) (b(1)).*x.*(2.*pi.*h.*(c^2)./(x.^5)).*(1./(exp((h.*c)./(x.*kb.*b(2)))-1));
beta0 = [2.2e-27 ;3e4];
[beta,R,J,CovB,MSE,ErrorModelInfo] = nlinfit(x,y,BBfun,beta0);
%Output values and errors
% b1 is alplha multiplication factor = (R/D)^2, detnoted A. b2 is temp
ci = nlparci(beta,R,"Covar",CovB);
errA = (((ci(1,2)) – (ci(1,1)))/2);
errTemp = ((ci(2,2) – ci(2,1))/2);
A = ((beta(1,1)));
Temp = beta(2,1);
Rad = sqrt(A)*1.85e+24; %convert to radius, distance to transient 1.85e+24
errRad = Rad*sqrt(((0.5*errA)/A)^2 + (4.19e+22/1.85e+24)^2); %error propagation from aplha and distance
%stephan-boltzmann constant
sb = 5.67e-08;
Lum = (4*pi*Rad^2*sb*Temp^4)*1e7; %in erg/s
errLum = Lum*sqrt((2*errRad/Rad)^2 + (4*errTemp/Temp)^2);
results(i,1) = A;
results(i,2) = errA;
results(i,3) = Rad;
results(i,4) = errRad;
results(i,5) = Temp;
results(i,6) = errTemp;
results(i,7) = Lum;
results(i,8) = errLum;
%plot fit
hold on
plot(x,BBfun(beta,x),’-r’);
hold off
end
%final plots
time = [3.4421, 4.2246, 5.695, 6.6946, 7.0809, 7.2812, 8.8125, 9.6112, 10.6128, 11.5382, 11.6742, 13.3953, 14.7236, 15.6233, 16.7919, 17.0436, 18.7829, 19.1707, 20.6369, 21.7721, 22.1614, 22.1619, 23.1565, 23.1571, 23.7631, 24.2266, 25.2168, 26.1579, 26.7577, 27.4169, 29.7512, 31.5264, 33.9284, 35.2449, 37.2385, 38.8981, 39.1618, 40.3597, 41.1686, 42.1524, 44.2117, 45.8706, 46.9335, 47.2638, 48.4002, 50.1866, 52.4438, 55.7044, 60.2141, 69.4632];
figure
t=tiledlayout(3,1,’TileSpacing’,’none’);
nexttile;
errorbar(time, results(:,7), results(:,8), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Luminosity (erg/s)’)
title(‘Luminosity over time’)
set(gca, ‘YScale’, ‘log’)
ytickformat(‘%.1e’)
ylim([6e41 4e45])
nexttile;
errorbar(time, results(:,3), results(:,4), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Radius (m)’)
%title(‘Radius over time’)
ax2 = gca;
ax2.YAxis.Exponent = 0;
ytickformat(‘%.1e’)
ylim([2.5e11 2.5e13])
nexttile;
errorbar(time, results(:,5), results(:,6), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Temperature (K)’)
%title(‘Temperature over time’)
ax3 = gca;
ax3.YAxis.Exponent = 0;
ytickformat(‘%.1e’)
ylim([0 4e4])
The file needed to run the code is attached as well. nlinfit, nonlinear, astronomy, astrophysics, blackbody, matlab, curve fitting, parameters, fitting, statistics, physics MATLAB Answers — New Questions









