Plot data for unique temperatures imported from text file

Hello,
I would like to plot the reaction against concentration on a 3 by 1 subplot for each unique temperature in the imported text data file. I think I need to put it in a loop but I'm not sure how to get it to plot.
Any help is appreciated, the code I have so far is below and text file ('reactions.txt') is attached.

3 件のコメント

Rik
Rik 2020 年 10 月 19 日
Rik
Rik 2020 年 10 月 19 日
You're forgetting several things:
  • You are plotting the entire c and r vectors, not just the parts that belong to a specific temperature.
  • You use hold on before creating the first plot in the subplot axes.
  • The a variable describes positions in your temp array, not its values.
Cate may
Cate may 2020 年 10 月 19 日
編集済み: Rik 2020 年 10 月 19 日
hello thanks for the feedback, I've attached the actual code so it can run.
So how can I plot just the c and r vectors for the specific temperatures?
and how can I code the a variable so it describes the temp values and not its positions.
Thanks
%% code starts here
r_data = importdata('reactions.txt');
%reaction_data = r_data.data;
%fid=fopen('reactions.txt');
t = reaction_data(:,1); %temperatures in vector
c = reaction_data(:,2); % concentration
r = reaction_data(:,3); % reaction rate
temp = unique(t);
for a = 1:length(temp)
if a == 323
hold on
subplot (3,1,1)
plot(c,r)
elseif a==333
hold on
subplot(3,1,2)
plot(c,r)
elseif a ==343
hold on
subplot(3,1,3)
plot(c,r)
end
end

サインインしてコメントする。

 採用された回答

Rik
Rik 2020 年 10 月 19 日

2 投票

%% code starts here
r_data = importdata('reactions.txt');
%reaction_data = r_data.data;
%fid=fopen('reactions.txt');
t = reaction_data(:,1); %temperatures in vector
c = reaction_data(:,2); % concentration
r = reaction_data(:,3); % reaction rate
temp = unique(t);
for a = 1:length(temp)
L= t==temp(a) ;
if temp(a)==323
subplot (3,1,1)
plot(c(L),r(L))
elseif temp(a)==333
subplot(3,1,2)
plot(c(L),r(L))
elseif temp(a)==343
subplot(3,1,3)
plot(c(L),r(L))
else
warning('temperature of %.0f not plotted',temp(a))
end
end

1 件のコメント

Cate may
Cate may 2020 年 10 月 19 日
Thanks for all the help, greatly appreciated!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2020 年 10 月 19 日

コメント済み:

2020 年 10 月 19 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by