이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Help to plot a graph using the data file
조회 수: 62 (최근 30일)
이전 댓글 표시
I have the data filefor the velocity, for which i need aplot a graph.
답변 (1개)
Star Strider
2025년 12월 5일
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')
.
댓글 수: 29
Ruthra
2025년 12월 5일
Thanks for your answer, but i need my plot as the image attachd below, i have data txt for u velocity and v velocity separately, from that how can i plot as the below graph

Star Strider
2025년 12월 5일
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'.
Ruthra
2025년 12월 5일
Thankyou, i have the separate datas for different AR, im not getting about the X, Y concept.And can you explain further about the 'paperclip'.
Star Strider
2025년 12월 5일
Star Strider
2025년 12월 5일
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
2025년 12월 6일
@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

Ruthra
2025년 12월 6일
No , i just need the graphs for 3 datas, i have plotted only for, AR= 0.4 to 0.6, the code he has given is been splitted, so i just asked the code from top to bottom , so i can run and see.
Star Strider
2025년 12월 6일
편집: Star Strider
2025년 12월 6일
@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
2025년 12월 6일
편집: Sam Chak
2025년 12월 6일
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
2025년 12월 6일
@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.
.
Ruthra
2025년 12월 19일 7:26
i have done the same but i didnt get the graph , its showing error, i will attach the code.Please check and say.
Star Strider
2025년 12월 19일 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.
Ruthra
2025년 12월 23일 8:43
Can you explain me clearly what are the changes i have to exactly in deep.
Star Strider
2025년 12월 23일 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
2026년 1월 5일 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
2026년 1월 5일 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
2026년 1월 7일 13:09
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')
.
Star Strider
대략 9시간 전
You have a script named 'grid.m' that is overshadowing with the MATLAB grid function.
You need to rename your 'grid.m' to something that is different from any of the MATLAB built-in functions.
(I assume the files are being read, so 'u{:}' and 'v{:}' have data.)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Data Preparation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)





