Help to plot a graph using the data file

60 views (last 30 days)
Ruthra
Ruthra on 5 Dec 2025
Commented: Star Strider on 7 Jan 2026 at 13:09
I have the data filefor the velocity, for which i need aplot a graph.

Answers (1)

Star Strider
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
Data = 11×2
0 0 1.0000 0.3090 2.0000 0.5878 3.0000 0.8090 4.0000 0.9511 5.0000 1.0000 6.0000 0.9511 7.0000 0.8090 8.0000 0.5878 9.0000 0.3090 10.0000 0.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Time = Data(:,1);
Velocity = Data(:,2);
figure
plot(Time, Velocity)
grid
axis('padded')
xlabel('Time')
ylabel('Veolcity')
title('Data')
.
  27 Comments
Star Strider
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')
.

Sign in to comment.

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!