Help to plot a graph using the data file

105 Ansichten (letzte 30 Tage)
Ruthra
Ruthra am 5 Dez. 2025 um 10:06
Kommentiert: Star Strider vor etwa 7 Stunden
I have the data filefor the velocity, for which i need aplot a graph.

Antworten (1)

Star Strider
Star Strider am 5 Dez. 2025 um 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
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')
.
  23 Kommentare
Ruthra
Ruthra vor etwa 9 Stunden
Can you explain me clearly what are the changes i have to exactly in deep.
Star Strider
Star Strider vor etwa 6 Stunden
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.
.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by