Cell Operation

조회 수: 2 (최근 30일)
Jing Hua
Jing Hua 2012년 6월 26일
Hi,
Does anyone know how to extract all arrays in a cell without mixing them all up in a single array (cell2mat) and at the same time using the loop.
clear all, clc
%Find the Boundaries of the Ellipse
I = imread('ellipse.png');
BW = im2bw(I, graythresh(I));
figure, imshow(BW);hold on
colors=['b' 'g' 'r' 'c' 'm' 'y'];
[B,L,N,A] = bwboundaries(BW);
%Get coordinates for each boundary
K=B{3};
x3=K(1:length(K),2);
y3=K(1:length(K),1);
E=B{4};
x4=E(1:length(E),2);
y4=E(1:length(E),1);
F=B{5};
x5=F(1:length(F),2);
y5=F(1:length(F),1);
G=B{6};
x6=G(1:length(G),2);
y6=G(1:length(G),1);
H=B{7};
x7=H(1:length(H),2);
y7=H(1:length(H),1);
J=B{8};
x8=J(1:length(J),2);
y8=J(1:length(J),1);
--------------------------------------- when I put those in a loop, is appears : bad cell operation
Thanks

답변 (1개)

Walter Roberson
Walter Roberson 2012년 6월 26일
colors={'b' 'g' 'r' 'c' 'm' 'y'};
Notice the change from [] to {}
Please copy the exact error message, and show which line MATLAB thinks the problem is on.
I notice that you are assuming that bwboundaries() is going to return a cell with at least 8 entries. It is not a good to assume that. If you need 8 results back, check the size of the cell array before you start indexing into it.
  댓글 수: 2
Jing Hua
Jing Hua 2012년 6월 26일
I need Cell B, and Cell B contains 8 arrays, and each array is n*2. I need to plot first column verses second column for each array. I there a better way, cuz when I use the loop X=B{i}(1:lengthB{i},1), i=1:length(B), it returns bad cell reference operation.
Walter Roberson
Walter Roberson 2012년 6월 26일
Please copy the exact error message, and show which line MATLAB thinks the problem is on.
bwboundaries() is not certain to have B contain 8 entries.
Please show class(B) and size(B)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by