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 个评论
Matt Kindig
2013-10-22
编辑:Matt Kindig
2013-10-22
What about
B = cell2mat(A{ii})
Hi Matt,
This is what i had, doesnt work....
采纳的回答
Type
A
whos A
what did you get?
13 个评论
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
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
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Read, Write, and Modify Image 的更多信息
标签
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
