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 Comments

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.
Find Attach file icon, next to the Help button.
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^

Sign in to comment.

 Accepted Answer

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 Comments

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. :)

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!