Plot the last value from each cell from excel file

6 visualizzazioni (ultimi 30 giorni)
Hi there,
This is a following question for here:
I applied the way they suggested but I don't get the exact value! Most of the last value in each cell is 50 but I don't get that. Could you please provide me the best way to extract the last values in each cell and plot it?
max_iterations = 500;
xs = 1 : max_iterations;
N1 = importdata('transRewards_40_1_2.csv'); %new trans with modi
N1 =N1{1};
N1 = strrep(N1, '"[', "");
N1 = strrep(N1, ']"', "");
N1 = sscanf(N1, '%f, ', inf);
r1 = mean(reshape(N1,40,[]), 1);
r1 = r1';
ys_01 =r1(1:max_iterations, 1);
plot(xs, ys_01,'Color',[0.75, 0.75, 0]);
The data I mentioned in attachments
  1 Commento
Stephen23
Stephen23 il 26 Set 2022
"Plot the last value from each cell from excel file"
What Excel file? The file you uploaded is a text file, something that exists completely independently of MS Excel.

Accedi per commentare.

Risposta accettata

Stephen23
Stephen23 il 26 Set 2022
Modificato: Stephen23 il 26 Set 2022
"Could you please provide me the best way to extract the last values in each cell and plot it?"
Sure, I already did that sixteen days ago, here. The method I showed you works as expected, giving the complete matrix, allowing you to trivially select all of the values in the last column. Of course, if you want to use more complex, fragile approaches, that is up to you.
M = readmatrix('transRewards_40_1_2.csv', 'LineEnding',']', 'TrimNonNumeric',true)
M = 1000×20
-23.0000 17.3612 17.5545 22.3577 27.5807 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 -30.0000 18.7539 19.4336 25.2898 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 -25.0000 15.3324 17.2834 23.4439 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 -26.0000 11.5028 11.8822 15.5847 25.2302 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 -32.0000 18.3882 20.9653 24.7008 28.8090 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 -33.0000 15.2701 16.7847 19.2218 23.5090 31.2725 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 -28.0000 14.8581 16.6499 20.8078 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 -33.0000 15.6013 18.0768 22.9376 28.0860 32.7748 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 -43.0000 17.1061 18.5248 21.7908 24.6967 28.7479 39.5083 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 -43.0000 17.9788 20.0599 22.7584 26.3272 32.4191 41.1214 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000
plot(M(:,end))
  1 Commento
Stephen23
Stephen23 il 26 Set 2022
Modificato: Stephen23 il 26 Set 2022
For comparison I reformatted that text file into a proper CSV file (not like the original abomination):
M = csvread('transRewards_40_1_2_modified.csv')
M = 1000×20
-23.0000 12.1692 12.3402 17.8976 23.0000 23.0000 23.0000 23.0000 23.0000 23.0000 23.0000 23.0000 23.0000 23.0000 23.0000 23.0000 23.0000 23.0000 23.0000 23.0000 -31.0000 17.3612 17.5545 22.3577 27.5807 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 31.0000 -30.0000 18.7539 19.4336 25.2898 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 30.0000 -25.0000 15.3324 17.2834 23.4439 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 -26.0000 11.5028 11.8822 15.5847 25.2302 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 26.0000 -32.0000 18.3882 20.9653 24.7008 28.8090 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 32.0000 -33.0000 15.2701 16.7847 19.2218 23.5090 31.2725 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 -28.0000 14.8581 16.6499 20.8078 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 28.0000 -33.0000 15.6013 18.0768 22.9376 28.0860 32.7748 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 33.0000 -43.0000 17.1061 18.5248 21.7908 24.6967 28.7479 39.5083 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000 43.0000
plot(M(:,end))
So far everything is working exactly as expected.

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by