![combo.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253746/combo.png)
Plot by loading a vector, saved from a different workspace as .mat file(converting struct to vector)
2 次查看(过去 30 天)
显示 更早的评论
Hi,
im quite new to Matlab so sorry for the completely amateur question, but I need help.
I have alot of calculations done inside a loop where i change a value and get two vectors(Concentration and Height) that i use to plot.
My objective is to change the value of X from which the two vectors are calulated, from 0,5,10,15,20. And then plot for Concentration and Height corresponding to each of these values.
I though of manually go, and change the value -> run the code->save variable as a .mat file.
Make a new code and define them as a new variable with the load command.
And then make a plot from each of these loaded vectors. But when i load them, the are converted into a 1x1 struct and i get a "Error using plot Invalid data argument".
My question is.
Is there any other way to plot it or can i somehow convert the loaded file from a struct to a vector that i define?
I attached the variables.mat files and this is the code.
Best Regards
Saad Khan
%Code for loading the variables, OBS! Make sure .mat files are in same
%folder as this file!!!
%Loading of variables%
He10=load('He_10.mat');
c10=load('c_10.mat');
He15=load('He_15.mat');
c15=load('c_15.mat');
He20=load('He_20.mat');
c20=load('c_20.mat');
%plot
figure(1)
plot(He10,c10(1:length(He10),1),'-r',He15,c15(1:length(He15),1),'-g',He20,c20(1:length(He20),1),'-b');
xlabel('Height[m]')
ylabel('CO Concentration[vol%]')
legend('O2=10%','O2=15%','O2=20%')
title('CO optimal at different O2 concentrations')
saveas(figure(1),'combo.png')
0 个评论
采纳的回答
Stephen23
2019-12-10
编辑:Stephen23
2019-12-10
Use a loop, e.g.:
D = 'temp'; % path of the folder where the files are saved.
N = [10,15,20];
C = 'rgb';
for k = 1:numel(N)
F = sprintf('He_%d.mat',N(k));
S1 = load(fullfile(D,F));
F = sprintf('c_%d.mat',N(k));
S2 = load(fullfile(D,F));
X = S1.He;
Y = S2.c(1:numel(X));
plot(X,Y,['-*',C(k)])
hold('on')
end
xlabel('Height[m]')
ylabel('CO Concentration[vol%]')
legend('O2=10%','O2=15%','O2=20%')
title('CO optimal at different O2 concentrations')
saveas(figure(1),'combo.png')
Giving (note that your data mostly overlap, but some green and red points are visible too):
![combo.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253746/combo.png)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!