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

how to take the first element from two cell array in single for loop

2 Comments

How do you create your ‘CHM’ cell array?
Your code is displaying the first 6 elements of it.
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.

Sign in to comment.

 Accepted Answer

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 Comments

hey stinder can u help me again..
if you can want to see the cell array A and B then go top of this message
I don’t understand your new question.
It would probably be best for you to post it as a new question anyway, and with significantly more detail.
Please be as specific as you can in describing exactly what you want to do.
basically what it is nodes which are placed on the 2d graph but i would to connect with line. you were solved my problem approx 4 hours ago.now with this code i create two arrays first one is below
and second one array is below
nodes(eg:-1,9,4,12 etc)
now i wish to draw a line on 2d graph between two nodes because these nodes are plotted on the 2d graph
like node no 1 from array A and node no 7 from array B
node no 9 from array A and node no 10 from array B
node 4 from node array A and node no 7 from array B
So on
I still don’t have any idea what you want to do. That is probably because it is far from my areas of expertise, so I do not recognise it. If you are doing graph theory, it would likely be better for someone with a background in it to reply.
There might be a Simulink toolbox that would do what you want. I only have basic Simulink (that I have not used recently). It does not to my knowledge do graph theory.
I don't see the logic here, either...
1 from A and 7 from B --> A(1,1)--B(1,1)
OK, I can dig that
9 from A and 10 from B --> A(2,1)--B(1,2)
OK, maybe we're going thru and associating by linear position overall...
4 from A and 7 from B --> A(3,1)--B(1,1)
Ooops!!! That's going back to the beginning in B again. Why? How are we to know who to pick from where; it seems arbitrary (or at least there aren't enough examples given to discern the pattern).
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
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;

Sign in to comment.

More Answers (1)

>> 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
>>

Categories

Asked:

on 26 Apr 2015

Commented:

dpb
on 27 Apr 2015

Community Treasure Hunt

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

Start Hunting!