MATLAB Answers

Variable TempData must be of size [25 33]. It is currently of size [31 24]. Check where the variable is assigned a value.

7 views (last 30 days)
% read excel file
TempData = readmatrix ("Clemson_Temp.xlsx");
% trim TempData
TempData=TempData(2:end,3:end);
% calculate monthly maximum
MonthMax=max(TempData(1:2:24,:)')
% calculate monthly minimum
MonthMin=min(TempData(2:2:24,:)')
The variable TempData needs to be [25 33] and is [31 24] how can I change it to be so?

Accepted Answer

Walter Roberson
Walter Roberson on 3 Jul 2020
You cannot do that.
After reducing by 1 row, your data ended up with 31 rows. Therefore it had 32 rows to start.
After reducing by 2 columns, your data ended up with 24 columns. Therefore it had 26 columns to start.
Suppose we take
TempData = readmatrix ("Clemson_Temp.xlsx") .'; %NOTICE THE TRANSPOSE
then TempData would be 26 rows and 32 columns (after the transpose.)
You can remove one row from that,
TempData = Tempdata(32:end,:);
and the result would be 25 rows and 32 columns. Which is close, but you need it to be 25 rows and 33 columns. You cannot "invent" the missing 33rd entry.
I suspect that the input had 33 rows but that the first row was interpreted as being a header and so was discarded by readmatrix. If you have reason to believe that the first row is valid data, then try
TempData = readmatrix("Clemson_Temp.xlsx", 'NumHeaderLines', 0) .'; %NOTICE THE TRANSPOSE
TempData = TempData(2:end,:);
  2 Comments
Walter Roberson
Walter Roberson on 3 Jul 2020
After you do
TempData = readmatrix ("Clemson_Temp.xlsx");
then what is size(TempData) ?
Year =sprintf("Clemson_Temp.xlsx");
That line seems unlikely to be correct.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by