# Plot by loading a vector, saved from a different workspace as .mat file(converting struct to vector)

2 ビュー (過去 30 日間)
Saad Khan 2019 年 12 月 10 日
Edited: Stephen Cobeldick 2019 年 12 月 10 日
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
%Code for loading the variables, OBS! Make sure .mat files are in same
%folder as this file!!!
%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 件のコメント

サインイン to comment.

### 採用された回答

Stephen Cobeldick 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));
F = sprintf('c_%d.mat',N(k));
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):

#### 0 件のコメント

サインイン to comment.