Error- Assignment has more non-singleton rhs dimensions than non-singleton subscripts?

I'm trying to reshape data from a file(A), into a matrix(dcburn) that I made in a certain way using for loops. it keeps giving me this error. I tried doing it multiple ways this is one of them.
A = load('dc.burn.out.txt');
n = length(A);
dcburn = ones(214,223)*-99999;
numrow = 214;
numcol = 223;
k = 1:1:n;
for i = numrow:-1:1;
for j = 1:1:numcol;
dcburn(i,j) = A(k);
end
end

6 个评论

Check the size A(k)...it could be a vector and you are trying to save it into a single location
Your code is already shared. Your txt file is needed.
how can I share my data? and well yea I guess its a vector. it has the size of 47722 which is the exact same size for the matrix 214*233, so I'm just trying to input the numbers from data(A) on a certain way which is how I have my for loops set up.
so A is in the form of A(47722,1) and its just full of 0, 1, 2, 3, and 4s. i uploaded the file^

请先登录,再进行评论。

 采纳的回答

Well, your problem comes from the fact that you try to put your A vector into one single element of dcburn everytime and this will throw an error. You can either do it by using cell arrays, as follows(I think this is not what you intended to do):
A = load('dc.burn.out.txt');
n = length(A);
dcburn = num2cell(ones(214,223)*-99999);
numrow = 214;
numcol = 223;
k = 1:n;
for i = numrow:-1:1
for j = 1:1:numcol
dcburn{i,j} = A(k);
end
end
or you can simply use reshape function which will convert your vector to a matrix with predefined dimensions as follows, which will make it a numeric multidimensional array:
A = load('dc.burn.out.txt');
n = length(A);
dcburn=reshape(A,214,223)

4 个评论

So yea i get what you said, and well i ran that code but it wasn't giving me the actual number... it just gave me {47722x1 double} for basically the whole matrix. and the reason why i didn't use reshape is because the assignment is to reshape it without using "reshape" command. Isn't there another way to rewrite or add something else? Also because we haven't learned num2cell, thank you.
actually i think i got it... i ran this
A = load('dc.burn.out.txt');
n = length(A);
dcburn = ones(214,223)*-9999;
numrow = 214;
numcol = 223;
k = 1:1:n;
count = 0;
for i = numrow:-1:1;
for j = 1:1:numcol;
count = count + 1;
dcburn(i,j) = A(count);
end
end
Yes, this is also a way but very inefficient. Anyway, if your problem is solved, then there is nothing to say.
well thank you ill still accept your answer for helping me. :)

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by