Brace indexing is not supported for variables of this type

Hey all, When I try to use this code:
output = cell(size(new_precipitation));
for i = 1:length(new_precipitation)
mn2t_mat = new_precipitation{i}; % extract matrix of ith element
yd = max(max(mn2t_mat)); % first find maximum for each hour
y = reshape(yd,24,1,size(yd,3)/24); % reshape it by day
output{i} = max(y); % find maximum of each day
end
This error appeared:
Brace indexing is not supported for variables of this type.
I was search for some answer but can't find how to fix it. Do you have any idea how to overcome this error?
I attached a new_precipitation.mat file in the google drive which has 10 MB in this link:
Thank you in advance
Caption:
I have a 3D matrix named new_precipitation (latitude x longitude x time). In essence time dimension is in the hourly time steps for a year (365-day x 24 hours = 8760). Whole data are for temperature and I want to find the maximum temperature for each day instead of hourly.
24 values for each day that represents temperature so I need to find a maximum of 24 values in order to have the maximum temperature of each day.
So I need to find maximum value for every 24 by 24-time steps and consider it for days.
I'm sorry I forgot to change the name so new_precipitation is a wrong variable name of new_temperature.

2 Comments

What is class(new_precipitation) ?
class(new_precipitation)
ans =
'double'
Thank you

Sign in to comment.

 Accepted Answer

I think Walter was onto the right thing in his comment. new_precipitation is of type 'double' and so doesn't support brace (i.e. { } ) indexing. For that variable you'll want to change to ordinary round brackets (i.e. ( ) ). In other words, you'll need to change the third line to something like:
mn2t_mat = new_precipitation(i); % extract matrix of ith element

10 Comments

In addition, new_precipitation is a 3D double matrix:
What do you expect from length(new_precipitation)? length function gives the size of the largest matrix dimension...
Dear ME
I changed the third line to
mn2t_mat = new_precipitation(i); % extract matrix of ith element
But another error occurred:
Error using reshape
Size arguments must be real integers.
Thanks
length(new_precipitation)
ans =
8760
A better approach is (length function for multidimensional arrays is not a good idea):
size(new_precipitation,3)
ans =
8760
What do you expect for mn2t_mat?
mn2t_mat = new_precipitation(i); %This line gives you a scalar
I guess you want the 2D matrix, then:
mn2t_mat = new_precipitation(:,:,i); %This line gives you a 2D matrix
This is technically now a new question but anyway. Your issue now is that
size(yd)
ans =
1 1
but by trying to use size(yd,3), you are trying to take the third element of the above ans which obviously doesn't exist.
My guess based on your comment of
% extract matrix of ith element
is that for mn2t_mat you actually want to get a matrix output rather than the scalar that you are currently getting. As such, you'd need to change
mn2t_mat = new_precipitation(i);
to something more like
mn2t_mat = new_precipitation(:,:,i);
although which dimension you actually want, I haven't checked properly.
I think this is basically what Alex Mcaulley was saying but I must've been typing while he posted his answer!
I have a 3D matrix named new_precipitation (latitude x longitude x time). In essence time dimension is in the hourly time steps for a year (365-day x 24 hours = 8760). Whole data are for temperature and I want to find the maximum temperature for each day instead of hourly.
24 values for each day that represents temperature so I need to find a maximum of 24 values in order to have the maximum temperature of each day.
So I need to find maximum value for every 24 by 24-time steps and consider it for days.
I'm sorry I forgot to change the name so new_precipitation is a wrong variable name of new_temperature.
I think you want something like this:
output = zeros(size(new_precipitation)./[1,1,24]);
for i = 1:24:size(new_precipitation,3)
mn2t_mat = new_precipitation(:,:,i:i+23); % extract matrix corresponding to 24 hours of one day
yd = max(mn2t_mat,[],3); %calculate the maximum for each latitude, longitude
output(:,:,ceil(i/24)) = yd; % save the values of day i
end
Dear Alex Mcaulley
Thank you for your answer. I run this code and everything is ok. Sincerely I want to ask you if you please could send me a description of this code? because I think about it a couple of hours and as I'm not a professional I cant recognize what you do.
Is this code capture maximum values for every 24 by 24 rows and save it as a value for the days?
Thank you so much.
The best way to understand the code is to put breakpoints and go though it line per line seeing what happens in each iteration (reading the documentation in case you don't understand any function)
output = zeros(size(new_precipitation)./[1,1,24]); %Preallocation of the output matrix of size [20,16,365]
for i = 1:24:size(new_precipitation,3) %Loop to extract the values corresponding to 1 day
mn2t_mat = new_precipitation(:,:,i:i+23); %In mn2t_mat you have the values corresponding to 24 hours of 1 day
yd = max(mn2t_mat,[],3); %Here, we calculate the maximum for each latitude, longitude in this day
output(:,:,ceil(i/24)) = yd; % save the values of that day
end

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2018b

Asked:

BN
on 23 Jan 2020

Commented:

on 24 Jan 2020

Community Treasure Hunt

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

Start Hunting!