how to draw line from first element of cell array to same cell array but fliplr first element and soon

1 回表示 (過去 30 日間)
how to take the first element from two cell array in single for loop
  2 件のコメント
Star Strider
Star Strider 2015 年 4 月 26 日
How do you create your ‘CHM’ cell array?
Your code is displaying the first 6 elements of it.
Star Strider
Star Strider 2015 年 4 月 26 日
NOTE: This was not the original question (so those of us who Answered it are not as delusional as it might seem from reading our Answers).
The new question is correctly (and more understandably) stated in: how to draw a line from one plotted node to another ploted node.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2015 年 4 月 26 日
編集済み: Star Strider 2015 年 4 月 26 日
This is the easiest way to do what I believe you want:
CHM = {[] [] [17] [] [6,11] [1 9]};
A = CHM(cellfun(@(x) ~isempty(x), CHM));
A{:} % Display Contents Of ‘A’
produces:
ans =
17
ans =
6 11
ans =
1 9
EDIT: Added results of displaying ‘A’
  9 件のコメント
singh
singh 2015 年 4 月 27 日
ok star and dpb, forget last query suppose star give me solution
A = CHM(cellfun(@(x) ~isempty(x), CHM));
A{:} % Display Contents Of ‘A
B=fliplr(A) % Display Contents Of ‘B
now how to assign two different variable (C and D) values from two cells array A and B until both array will be end and plz used all in the single loop except A and B used in the loop
suppose variable C has first value of A and D has first value of B
now variable C has second value of A and D has second value of B
so on
dpb
dpb 2015 年 4 月 27 日
After the above (SS's solution) for A then it's simply
A=[A(:)]; % convert A cell array to row vector, NB: SS leaves as cell
B=fliplr(A); % now reverse for B
C=A; % make two copies (or assign C, D instead of A,B above)
D=B;

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2015 年 4 月 26 日
編集済み: dpb 2015 年 4 月 26 日
>> CHM={[];[];17;[];[6 11];[1 9]};
>> for i=1:length(CHM)
if ~isempty(CHM{i}) % NB "the curlies" {} in the addressing...
disp([num2str(i) ': ' num2str(CHM{i})])
end
end
3: 17
5: 6 11
6: 1 9
>>

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by