cell2mat with 1* 1 cell array

Folks,
I have A{ii} which is a cell array 1*1 containing 18*9 matrix. I atttempt to convert to a matrix using B=cell2mat(A) but I get error stating
Cell contents reference from a non-cell array object.
I cannot change A{ii} to A(ii) is it violates
A(I) = B, the number of elements in B and
I must be the same.
Any ideas? Regards B

2 Comments

What about
B = cell2mat(A{ii})
Hi Matt,
This is what i had, doesnt work....

Sign in to comment.

 Accepted Answer

Type
A
whos A
what did you get?

13 Comments

Try this
cell2mat([A{:}])
Hi Azzi,
No luck. The who function returns A as a 1*1 cell
What about
b=A{1}
whos b
bugatti79
bugatti79 on 23 Oct 2013
Edited: bugatti79 on 23 Oct 2013
Hi Azzi,
That seems to have worked in the for loop. Ie, I was able to create an 18*9 double matrix from a 1*1 cell containing 18*9 double using b=A{1} you advised. Can you explain what it is actually doing? Thanks in advanced B
Post your for loop
Actually, it doesnt work upon closer examination. b=A{1} means that it keeps the first matrix generated from the first loop and this carries through. I need to keep b as an index because in each loop b will be a different 18*9 matrix.
for ii=1:size(nu_1,3);
i=nu_1(:,:,ii);
A{ii}= i.*n.....
b=A{1}
c{ii}=b.*i %
end
whos
nu_1 18x9x6 double
A{ii} 1x1 cell
n 18*9 double
b 18x9 double
i 18*9 double
I can't understand what this code is doing. To make your question clear, post a short sample of your data, then ask what you want
[bugatti79 commented]
Here is the code
nu = [25 25; 25 25]';
nu_1=nu;
nu_1(:,:,2)=50;
nu_1(:,:,3)=150;
nu_1(:,:,4)=300;
nu_1(:,:,5)=400;
nu_1(:,:,6)=450;
n=[ 100 100; 200 200]
for ii=1:size(nu_1,3)
i = nu_1(:,:,ii);
A(ii) = n.*i;
B(ii) =c.*i.*n; % c a constant
C(ii)= i.*n.*B(ii).*C(ii)
end
If I run this code i get error..." A(I) = B, the number of elements in B and I must be the same. "
This is the problem that comes up as outlined in my first post on this thread... Hope this is clearer, thanks B
There are many errors in your code. you can't use A(ii)=matrix , you should use a cell array A{ii} with curly brackets. Another problem is this
C(ii)= i.*n.*B(ii).*C(ii) % What is the value of C(ii) for ii=1?
Try to adapt this
clear
c=1;
nu = [25 25; 25 25]';
nu_1=nu;
nu_1(:,:,2)=50;
nu_1(:,:,3)=150;
nu_1(:,:,4)=300;
nu_1(:,:,5)=400;
nu_1(:,:,6)=450;
n=[ 100 100; 200 200]
C{1}=ones(size(nu));
for ii=1:size(nu_1,3)
i = nu_1(:,:,ii);
A{ii} = n.*i;
B{ii} =c.*i.*n; % c a constant
C{ii+1}= i.*n.*B{ii}.*C{ii}
end
My apologies,
C{ii}= i.*n.*B{ii}.*C{ii}
should read
D{ii}= i.*n.*B{ii}.*C{ii}
That should be workable now wit h your code right? Ie, just drop the +1?
Ok, but what is the value of C?
C needs to be a matrix not a single numeric value...
Then just use
D{ii}= i.*n.*B{ii}.*C

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!