Operating on CSV file as a matrix

59 次查看(过去 30 天)
Dear all.
I'm a low to medium level user of Matlab (mainly for analysing data and plotting, not strong in coding),
I have a trivial question, maybe it's easy fro you, but I'm stucked.
I've imported my CSV file as a numeric matrix (1064X561), I'd like to extract some data from it and plot them (firstly the mean of all rows, columns and the max of all rows and columns).
The basic commands I'm using (S is the matrix):
M = mean(S);
M2 = mean(S,2);
Max = max(S);
Max2 = max(S,2);
I've imported the data with semicolon delimiters, I know there's some issues in the values (a factor of 100, maybe different numeric format?),
but the big deal is I did get the two mean and the max for columns, but when I'm checking the row max is a 1064X561 matrix, while
it has to be a 1X561.
What did I do wrong? Is there an easy way to get this?
Any help is appreciated,
Thanks a lot

采纳的回答

Walter Roberson
Walter Roberson 2021-3-16
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/552082/Starch%20300g%203.5bar%20coarse_20201209_163713_20201209_163915_DF+20_Intensitychart.xls.csv';
S = readmatrix(filename, 'Delimiter', ';', 'DecimalSeparator', ',');
size(S)
ans = 1×2
1063 561
M = mean(S);
size(M)
ans = 1×2
1 561
M2 = mean(S,2);
size(M2)
ans = 1×2
1063 1
Max = max(S);
size(Max)
ans = 1×2
1 561
Max2 = max(S,[],2);
size(Max2)
ans = 1×2
1063 1
  2 个评论
Enrico Danzi
Enrico Danzi 2021-3-16
Thanks for the super quick reply, now I'm able to get the matrix well imported.
There's still one issue with the data, when I'm trying to get:
height = [1:1:1063];
line(height, Max2);
it's working up to 200, then it goes wrong (picking the "height" numeric values instead)
Why?
Thanks again...
Enrico Danzi
Enrico Danzi 2021-3-16
Nevermind, I've solved it.
It was a column with non valid values which gave me this "strange" behavior.
Thanks a lot.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by