# How to explain the code below in the loop so I reduce the lines

1 view (last 30 days)
muhammad choudhry on 5 Jan 2022
Commented: Image Analyst on 5 Jan 2022
Hi,
Below code is reading the data from the different folders and csv files and plotting them onto one figure but I want to reduce the code and write into the loop so that loop will follow the path of each folder one by one and plot the data of the different excel files on one graph. you help will be appreciated.
Code:
close all; clear all; clc;
%plot the data for Data_LaserSheet_D
X=a{:,5}/1000;
Y=a{:,6}/1000;
U=a{:,9};
V=a{:,10};
quiver(X,Y,U,V,10);
axis tight
hold on
%plot the data for Data_LaserSheet_C
X1=a1{:,5}/1000;
Y1=a1{:,6}/1000;
U1=a1{:,9};
V1=a1{:,10};
quiver(X1,Y1,U1,V1,10);
axis tight
hold on
%plot the data for Data_LaserSheet_B
X2=a2{:,5}/1000;
Y2=a2{:,6}/1000;
U2=a2{:,9};
V2=a2{:,10};
quiver(X2,Y2,U2,V2,10);
axis tight
hold on
%plot the data for Data_LaserSheet_A
X3=a3{:,5}/1000;
Y3=a3{:,6}/1000;
U3=a3{:,9};
V3=a3{:,10};
quiver(X3,Y3,U3,V3,10);
axis tight
hold on

Les Beckham on 5 Jan 2022
This would be a lot easier if all of the csv files were in the same folder. You could then use the dir cmd to get a list of the files and loop through them.
However, since you seem to know the exact files that you want to operate on, you can manually create this list first and then loop through the list to make the plot.
files = { 'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_PIV\Data_Vector\Run 13-56-31.Adaptive PIV.6tvk0mbp\Export.6tvk0mbp.000000.csv'; ...
for i = 1:numel(files)
X = a{:,5}/1000;
Y = a{:,6}/1000;
U = a{:,9};
V = a{:,10};
quiver(X, Y, U, V, 10);
axis tight
hold on
end
Stephen23 on 5 Jan 2022
Edited: Stephen23 on 5 Jan 2022
"what does '**' means in this case? "
Searches directories recursively, just as the documentation states:
"Brace indexing is not supported for variables of this type."
FullFileName is the chararacter vector returned by FULLFILE, why are you trying to use curly braces on a character vector? Anyway, you have already used indexing into theFiles, so why repeat the indexing again?
% ^^^ get rid of these
Image Analyst on 5 Jan 2022
In short, having ** allows it to recurse into subfolders rather than just searching one folder.