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
68 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 at 11:14
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')
.
19 Comments
Star Strider
about 1 hour ago
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
1 minute ago
Star Strider
about 1 hour ago
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
9 minutes ago
@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
33 minutes ago
Edited: Star Strider
30 minutes ago
@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
about 4 hours ago
Edited: Sam Chak
about 4 hours ago
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
about 3 hours ago
@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.
.
See Also
Categories
Find more on 2-D and 3-D Plots 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 (한국어)



