You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Help to plot a graph using the data file
60 views (last 30 days)
Show older comments
I have the data filefor the velocity, for which i need aplot a graph.
Answers (1)
Star Strider
on 5 Dec 2025
Perhaps something like this --
writematrix([0:10; sin(2*pi*(0:10)/20)].','Your_Data.csv') % Create File
Data = readmatrix('Your_Data.csv') % Read File
Time = Data(:,1);
Velocity = Data(:,2);
figure
plot(Time, Velocity)
grid
axis('padded')
xlabel('Time')
ylabel('Veolcity')
title('Data')
.
27 Comments
Star Strider
on 5 Dec 2025
That should be relatively straightforward.
If you upload your data (use the 'paperclip' icon in the top toolbar and follow the directions), I will see if I can reproduce those plots. The file should have the data for 'X', 'Y', 'U', and 'V', clearly labelled for various values of 'AR'.
Star Strider
on 5 Dec 2025
Star Strider
on 5 Dec 2025
I finally came up with a way to separate the files. It is not as straightforward as simply loading them and plotting them if they were originally given different names, however it distinguishes them and then plots them.
These appear similar to what you want, however I am not certain exactly what that is. (The resulting matrices are size (51x51) so I randomly chose the approximate centre of each (row/column 26) and plotted them. Yopu can set 'row_col' to be a vector (for exaample row_col = [1 26 51]) to plot multiple values from each matrix.
I have no idea what the 'AR' values are or how they relate to these matrices, so I just referred to the individual curves by the file names (that I assigned to them).
Try something like this --
filesc = {'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1844326/uvelo-vor.txt'; 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1844327/vvelo-vor.txt'; 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1844328/uvelo-vor.txt'; 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1844329/vvelo-vor.txt'; 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1844330/uvelo-vor.txt'; 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1844331/vvelo-vor.txt'}
filesc = 6×1 cell array
{'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1844326/uvelo-vor.txt'}
{'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1844327/vvelo-vor.txt'}
{'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1844328/uvelo-vor.txt'}
{'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1844329/vvelo-vor.txt'}
{'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1844330/uvelo-vor.txt'}
{'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1844331/vvelo-vor.txt'}
for k = 1:floor(numel(filesc)/2)
ki = 2*k-1;
filenameu{k,:} = sprintf('uvelo-vor%d.txt',k);
ufile = websave('uvelo-vor', filesc{ki});
u{k} = readmatrix(ufile);
Uu = unique(u{k}(:,1));
ux{k} = reshape(u{k}(:,1), numel(Uu), []);
uy{k} = reshape(u{k}(:,2), numel(Uu), []);
uz{k} = reshape(u{k}(:,3), numel(Uu), []);
% u{k}
end
for k = 1:floor(numel(filesc)/2)
ki = 2*k;
filenamev{k,:} = sprintf('vvelo-vor%d.txt',k);
vfile = websave('vvelo-vor', filesc{ki});
v{k} = readmatrix(vfile);
Uv = unique(u{k}(:,1));
vx{k} = reshape(v{k}(:,1), numel(Uv), []);
vy{k} = reshape(v{k}(:,2), numel(Uv), []);
vz{k} = reshape(v{k}(:,3), numel(Uv), []);
% v{k}
end
row_col = 26
row_col = 26
figure
hold on
for k = 1:3
plot(uz{k}(:,row_col), uy{k}(:,row_col), DisplayName=filenameu{k})
end
hold off
grid
xlabel('U')
ylabel('Y')
title('''U'' Matrices')
legend(Location='best')

●
figure
hold on
for k = 1:3
plot(vx{k}(row_col,:), vz{k}(:,row_col), DisplayName=filenamev{k})
end
hold off
grid
xlabel('X')
ylabel('V')
title('''V'' Matrices')
legend(Location='best')

.
Sam Chak
on 6 Dec 2025
@Ruthra, I hope the flag doesn't turn crimson. Which part of @Star Strider's code is incomplete? I can plot them using the same code and the indistinct data files you shared. Do you mean there should be four AR graphs instead of three?
figure

●
figure

Star Strider
on 6 Dec 2025
Edited: Star Strider
on 6 Dec 2025
@Ruthra --
My pleasure!
What I posted is the complete code. To copy all of it to your Clipboard, right-click on the 'Copy' icon in the upper right of the code section HERE
then paste that to an open tab in your MATLAB Editor.
For reference, the complete part of that line of code (the first line in my code) is this --
I had to figure out a way to separate the identically-named files into different files, and managed to do that. You will most klikely need to create a cell arrray of the complete paths to each of your files to your version of my 'filesc' cell array. Since the files themselves have identical names, they most likely exist in separate paths or at least directories, and my code needs to know where to find them.
Each file is actually 3 column vectors that the reshape function converts to (51x51) matrices of the 'x', 'y', and 'z' coordinates. I created those as individual cell arrays, since that makes indexing them easier. (I could have plotted those using the surf or similar functions. I decided not to since that was not requested.)
I suggest that you give unique names to your files., for example by appending numbers to them That will make this task much easier.
I have no idea what you actually want to plot, so I chose row or column 26 and plotted those from each file. You will need to experiment to see what rows or columns to plot.
I have no idea what the AR variable refers to. That information was not provided in connection with the files posted.
If my answer solves your problem, please Accept it!
.
EDIT -- Corrected minor formatting issue. Content unchanged.
.
Sam Chak
on 6 Dec 2025
Edited: Sam Chak
on 6 Dec 2025
Upon re-examining the situation, I believe that the identically named data files are "unprocessed" and retrieved from different folders categorized by varying AR values, as most systems do not permit two files with the exact same name and extension in the same folder. This likely explains why @Ruthra uploaded the data files across three separate comments above.
Some legacy machines or MATLAB codes may generate default filenames in this manner. In contrast, modern approaches typically create sequential filenames with the date and time appended to the end of the sequential number. This practice is generally beneficial for sorting data files chronologically.
Therefore, I sincerely believe that the code may need to be adjusted to account for @Ruthra's actual situation, and should post in a new Answer.
However, your solution to work with identically named files deserves a vote! 👍
Star Strider
on 6 Dec 2025
@Sam Chak -- Thank you!
Copying the complete paths to each file to create the'filec' cell array would then only require changing:
ufile = websave('uvelo-vor', filesc{ki});
u{k} = readmatrix(ufile);
and:
vfile = websave('vvelo-vor', filesc{ki});
v{k} = readmatrix(vfile);
to:
u{k} = readmatrix(filesc{ki});
and:
v{k} = readmatrix(filesc{ki});
in their appropriate loops, respectively.
The rest is unchanged.
.
Star Strider
on 19 Dec 2025 at 11:13
You do not need to use websave if the files are on your own computer, or available locally on a server. Just put the file names, each with a complete path to the file, in a cell array and use readmatrix to import them.
The problem is that the files have the same names, so you need to use the complete path to each of them, since they are probably in different directories, to read them correctly.
Star Strider
on 23 Dec 2025 at 12:25
You will need to copy the paths to each file to the 'filesc' cell array, and then use those in the readmatrix calls in your code.
That would go something like this --
filesc = {'/YourBaseFilePath/YourInstrumentPath_1/uvelo-vor.txt'; '/YourBaseFilePath/YourInstrumentPath_1/vvelo-vor.txt'; '/YourBaseFilePath/YourInstrumentPath_2/uvelo-vor.txt'; '/YourBaseFilePath/YourInstrumentPath_2/vvelo-vor.txt'; '/YourBaseFilePath/YourInstrumentPath_3/uvelo-vor.txt'; '/YourBaseFilePath/YourInstrumentPath_3/vvelo-vor.txt'};
for k = 1:floor(numel(filesc)/2)
ki = 2*k-1;
filenameu{k,:} = sprintf('uvelo-vor%d.txt',k);
u{k} = readmatrix(filesc{ki});
Uu = unique(u{k}(:,1));
ux{k} = reshape(u{k}(:,1), numel(Uu), []);
uy{k} = reshape(u{k}(:,2), numel(Uu), []);
uz{k} = reshape(u{k}(:,3), numel(Uu), []);
% u{k}
end
for k = 1:floor(numel(filesc)/2)
ki = 2*k;
filenamev{k,:} = sprintf('vvelo-vor%d.txt',k);
v{k} = readmatrix(filesc{ki});
Uv = unique(u{k}(:,1));
vx{k} = reshape(v{k}(:,1), numel(Uv), []);
vy{k} = reshape(v{k}(:,2), numel(Uv), []);
vz{k} = reshape(v{k}(:,3), numel(Uv), []);
% v{k}
end
row_col = 26
figure
hold on
for k = 1:3
plot(uz{k}(:,row_col), uy{k}(:,row_col), DisplayName=filenameu{k})
end
hold off
grid
xlabel('U')
ylabel('Y')
title('''U'' Matrices')
legend(Location='best')
figure
hold on
for k = 1:3
plot(vx{k}(row_col,:), vz{k}(:,row_col), DisplayName=filenamev{k})
end
hold off
grid
xlabel('X')
ylabel('V')
title('''V'' Matrices')
legend(Location='best')
I do not know what operating system you are using, or how your file paths are structured, so I use
'/YourBaseFilePath/YourInstrumentPath_1/'
and so fortth, for that here.
I strongly suspect that your instrument is creating something similar to 'YourInstrumentPath_1' (with slightly different names that I use numbers for here) for each 'uvelo-vor.txt' and 'vvelo-vor.txt' file pair it creates. You need to provide those details, since I have no idea what they are on your computer, or how any of that is organised.
I have changed the rest of my code to use those file paths directly to read and plot your files. You will need to choose the correct values for 'row_col' (there may be more than one, in that event you can create a vector for them) and the code should work as written here without any other midifications.
.
Ruthra
on 5 Jan 2026 at 9:06
the above is the modified code, but still im not getting the graph
filesc = {'D:/matlab programs/uvelo1-vor.txt'; 'D:/matlab programs/vvelo1-vor.txt'; 'D:/matlab programs/uvelo2-vor.txt'; 'D:/matlab programs/vvelo2-vor.txt'; 'D:/matlab programs/uvelo3-vor.txt'; 'D:/matlab programs/vvelo3-vor.txt'};
for k = 1:floor(numel(filesc)/2)
ki = 2*k-1;
filenameu{k,:} = sprintf('uvelo-vor%d.txt',k);
u{k} = readmatrix(filesc{ki});
Uu = unique(u{k}(:,1));
ux{k} = reshape(u{k}(:,1), numel(Uu), []);
uy{k} = reshape(u{k}(:,2), numel(Uu), []);
uz{k} = reshape(u{k}(:,3), numel(Uu), []);
% u{k}
end
for k = 1:floor(numel(filesc)/2)
ki = 2*k;
filenamev{k,:} = sprintf('vvelo-vor%d.txt',k);
v{k} = readmatrix(filesc{ki});
Uv = unique(u{k}(:,1));
vx{k} = reshape(v{k}(:,1), numel(Uv), []);
vy{k} = reshape(v{k}(:,2), numel(Uv), []);
vz{k} = reshape(v{k}(:,3), numel(Uv), []);
% v{k}
end
row_col = 26
figure
hold on
for k = 1:3
plot(uz{k}(:,row_col), uy{k}(:,row_col), DisplayName=filenameu{k})
end
hold off
grid
xlabel('U')
ylabel('Y')
title('''U'' Matrices')
legend(Location='best')
figure
hold on
for k = 1:3
plot(vx{k}(row_col,:), vz{k}(:,row_col), DisplayName=filenamev{k})
end
hold off
grid
xlabel('X')
ylabel('V')
title('''V'' Matrices')
legend(Location='best')
Star Strider
on 5 Jan 2026 at 12:02
Please right-click on each occurrence of the 'uvelo-vor.txt' and 'vvelo-vor.txt' files, then click on 'Properties' in the drop-down menu that opens, and copy the 'Parent Folder' or 'Path' string and paste that result, along with the file name, to a Comment here.
That is the information that needs to be in the 'filesc' array.
I cannot test it here because I do not have access to your computer. I can help you create the correct 'filesc' array.
Star Strider
about 2 hours ago
I tested it as far as I could, and it appears to assign the file names correctly. I re-tested my code as well, and it seems to work correctly.
Does your version of my code throw any errors or warnings?
Does it read the data? Check to see if there is anything in 'u{k}' and 'v{k}'.
I cannot determine if this is significant, however I note that is says that it opens with 'Notepad'. I no longer have access to Windows (I currently run Ubuntu on both my desktop and laptop), however it might be worthwhile changing that to open with 'MATLAB' or 'MATLAB Editor'.
Since I do not have access to your computer, you probably need to have someone in your research group help you determine what the problem is. My code works, however you need to get it to read your files. I cannot help you with that, beyond what I have already written. (The forward slants (/) should work in Windows, although Windows conventionally uses the back slant (\) as a separator. I doubt that is the problem.)
filesc = {'D:/matlab programs/uvelo1-vor.txt'; 'D:/matlab programs/vvelo1-vor.txt'; 'D:/matlab programs/uvelo2-vor.txt'; 'D:/matlab programs/vvelo2-vor.txt'; 'D:/matlab programs/uvelo3-vor.txt'; 'D:/matlab programs/vvelo3-vor.txt'};
for k = 1:floor(numel(filesc)/2)
ki = 2*k-1;
filenameu{k,:} = sprintf('uvelo-vor%d.txt',k)
% u{k} = readmatrix(filesc{ki});
% Uu = unique(u{k}(:,1));
% ux{k} = reshape(u{k}(:,1), numel(Uu), []);
% uy{k} = reshape(u{k}(:,2), numel(Uu), []);
% uz{k} = reshape(u{k}(:,3), numel(Uu), []);
% % u{k}
end
filenameu = 1×1 cell array
{'uvelo-vor1.txt'}
filenameu = 2×1 cell array
{'uvelo-vor1.txt'}
{'uvelo-vor2.txt'}
filenameu = 3×1 cell array
{'uvelo-vor1.txt'}
{'uvelo-vor2.txt'}
{'uvelo-vor3.txt'}
for k = 1:floor(numel(filesc)/2)
ki = 2*k;
filenamev{k,:} = sprintf('vvelo-vor%d.txt',k)
% v{k} = readmatrix(filesc{ki});
% Uv = unique(u{k}(:,1));
% vx{k} = reshape(v{k}(:,1), numel(Uv), []);
% vy{k} = reshape(v{k}(:,2), numel(Uv), []);
% vz{k} = reshape(v{k}(:,3), numel(Uv), []);
% v{k}
end
filenamev = 1×1 cell array
{'vvelo-vor1.txt'}
filenamev = 2×1 cell array
{'vvelo-vor1.txt'}
{'vvelo-vor2.txt'}
filenamev = 3×1 cell array
{'vvelo-vor1.txt'}
{'vvelo-vor2.txt'}
{'vvelo-vor3.txt'}
% row_col = 26
% figure
% hold on
% for k = 1:3
% plot(uz{k}(:,row_col), uy{k}(:,row_col), DisplayName=filenameu{k})
% end
% hold off
% grid
% xlabel('U')
% ylabel('Y')
% title('''U'' Matrices')
% legend(Location='best')
% figure
% hold on
% for k = 1:3
% plot(vx{k}(row_col,:), vz{k}(:,row_col), DisplayName=filenamev{k})
% end
% hold off
% grid
% xlabel('X')
% ylabel('V')
% title('''V'' Matrices')
% legend(Location='best')
.
See Also
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)




