How to reduce the line of the codes in the code given!
Afficher commentaires plus anciens
Hi,
I am plotting 3 sets of data on each graph and plotting 4 different graphs by reading the columns from the csv files. but seems like my code is way too long. I am stuck. Can any one have a go and reduce the amount of lines in my code:
CODE:
files = { 'F:\3-PIV_Experimental_Data\Outlet_110\ABCD_DesignPoint\Profile_Plot\Sheet_D\LSD_DataoverDistance.6vr3i20t.000010.csv'; ...
'F:\3-PIV_Experimental_Data\Outlet_110\ABCD_KickBack\Profile_Plot\Sheet_D\LSD_DataoverDistance.6vs3ia8s.000010.csv'; ...
'F:\3-PIV_Experimental_Data\Outlet_110\ABCD_flushflow\Profile_Plot\Sheet_D\LSD_DataoverDistance.6vs5mz18.000010.csv'};
for i = 1:numel(files)
a = readtable(files{i});
X = a{:,2};
Y = a{:,13};
figure(1)
plot(X,Y,'*');
hold on
%Spacing and griding of the plot
xlim([0 350])
ylim([0 2])
hold on
grid on
end
for i = 1:numel(files)
a = readtable(files{i});
X = a{:,16};
Y = a{:,27};
figure(2)
plot(X,Y,'*');
hold on
%Spacing and griding of the plot
xlim([0 350])
ylim([0 2])
hold on
grid on
end
for i = 1:numel(files)
a = readtable(files{i});
X = a{:,30};
Y = a{:,41};
figure(3)
plot(X,Y,'*');
hold on
%Spacing and griding of the plot
xlim([0 350])
ylim([0 2])
hold on
grid on
end
for i = 1:numel(files)
a = readtable(files{i});
X = a{:,44};
Y = a{:,55};
figure(4)
plot(X,Y,'*');
hold on
%Spacing and griding of the plot
xlim([0 350])
ylim([0 2])
hold on
grid on
end
Réponse acceptée
Plus de réponses (1)
William Rose
le 6 Fév 2022
You read each of the three files four separate times. Read them in once at the beginning, to tables a1, a2, a3. Keep them in memory. Assuming that you have done that, then you could replace the first for loop with the following (delete the for loop entirely):
figure;
plot(a1{:,2},a1{:,13},'r*',a2{:,2},a2{:,13},'go',a3{:,2},a3{:,13},'b^');
xlim([0 350]), ylim([0 2]), grid on
legend('a1','a2','a3');
Do likewise for the remaining three for loops.
Catégories
En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!