How can I store my data into a 2D array?

My code is attached below and it has the "Subscripted assignment dimension mismatch." error
How can I fix this? and how can I store my data into a 2D array? Thanks!

Antworten (3)

Renato Agurto
Renato Agurto am 16 Dez. 2015

0 Stimmen

Hi. The output of dec2bin is a char not a double. So you should define "out" as a cell:
[m,n] = size(x);
out = cell(m,n);
for i = 1:m
for j = 1:n
out{m,n} = dec2bin(abs(x(m,n)));
end
end
Cheers! Renato

2 Kommentare

Nic DC
Nic DC am 16 Dez. 2015
Hi Renato,
I tried doing your suggestion in defining 'out' as a cell and ran the program but then the output shown only brackets and 1 dec2bin conversion at the last element of the array
Renato Agurto
Renato Agurto am 16 Dez. 2015
Bearbeitet: Renato Agurto am 16 Dez. 2015
sorry, it should be:
out{i,j} = dec2bin(abs(x(i,j)));
;-)

Melden Sie sich an, um zu kommentieren.

Andrei Bobrov
Andrei Bobrov am 16 Dez. 2015

0 Stimmen

out = reshape(cellstr(dec2bin(abs(x))),size(x));

2 Kommentare

Nic DC
Nic DC am 16 Dez. 2015
Hi Andrei,
I tried doing your suggestion but this error occurred: "Error using cellstr Too many input arguments."
How do you suggest to go about this?
Andrei Bobrov
Andrei Bobrov am 16 Dez. 2015

Melden Sie sich an, um zu kommentieren.

Nic DC
Nic DC am 16 Dez. 2015

0 Stimmen

Hi Renato,
I tried doing your suggestion in defining 'out' as a cell and ran the program but then the output shown only brackets and 1 dec2bin conversion at the last element of the array

Kategorien

Gefragt:

am 16 Dez. 2015

Kommentiert:

am 16 Dez. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by