Help to plot a graph using the data file
117 次查看(过去 30 天)
显示 更早的评论
I have the data filefor the velocity, for which i need aplot a graph.
0 个评论
回答(1 个)
Star Strider
2025-12-5,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')
.
23 个评论
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.
.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







