Finding the indicies of the cell element

Hey all.
I asked this question already, But I didn't get the solution I intended.
I have a cell array
A = { [ 2 4 6] ['Air'; 'oil'; 'Metal']}
Here I am putting a part of my code.
for count = 1:n
if whichnode = find(X{1} == count, 1)
if ~isempty(whichnode)
whichnode = count;
% here I need to find the indicies of the count, which(number) will be there in matrix of the cell A{1}, I know using this, for an example if count = 4, it's indicies is A{1}(1,2). %This I can write manually, but I can't write it for each input. So I need to find the indicies for any input in A{1} again. One more example, if count = 9, it's indicies should be given automatically before the plot function.
plot(f, T1, 'DisplayName', A{2})
end
end
end
Here my Idea is to get the indices of the count in the matrix of the cell array, before the solver enter the built in function plot.
The reason is, using that indicies, I can display the name of the plot easily with my idea.
I don't know whether it is possible or not!. But If we get the idea, there should be a way to do it. I need that way.
Any suggestions and answered are most welcomed!
Thanks in advance

8 Comments

"I have a cell array"
A = { [ 2 4 6] ['Air'; 'oil'; 'Metal']}
I very much doubt that you have that cell array, because of the incompatible sizes of the character vectors:
>> ['Air'; 'oil'; 'Metal']
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Please upload the actual data, or specify valid MATLAB data.
[f,T1] = Samplemodel_Instat('Measuring_Data.mat');
[Lambda, A, B, D,V,H, Rho,cP,P, M, A1,O, X, M_1] = Matrix_Samplemodel;
A = { [ 2 4 6] ['Air '; 'oil '; 'Metal']}
or X = {[ 2 4 6] [ 'Node2'; 'Node4' ; 'Node6']}
figure('Color',[1 1 1])
for plotnumber = 1:n
whichnode = find(X{1} == plotnumber,1);
if ~isempty(whichnode)
% Here I need to find the indicies of the plotnumber, which(number) will be there in matrix of the cell A{1}, I know using this, for an example if count = 4, it's indicies is A{1}(1,2). %This I can write manually, but I can't write it for each input. So I need to find the indicies for any input in A{1} again. One more example, if plotnumber = 9, it's indicies should be given automatically before the plot function.
%plot(f(1:200:end)/3600,T1(plotnumber,1:200:end),'Color',[0.25 0.25 0.25],'LineWidth',4,'LineStyle','-.','MarkerFaceColor',[1 1 1],'Marker','none','DisplayName', X{2} );
end
end
Actual data it too big to paste here and also difficult to give the explanation to everything.
Thank you, I didn't notice the error intially.
I think now it is correct to get the solution.
Thanks in advance
@surendra kumar Aralapura mariyappa: Please use the buttons over the field for editing the message to format the parts. Let code look like code, and text like text. Use "M" to fomat Matlab expressions. This will increase the readability of your question.
As Stephen has written already, this line will cause an error:
A = { [ 2 4 6] ['Air '; 'oil '; 'Metal']}
Writing "or X = {[ 2 4 6] [ 'Node2'; 'Node4' ; 'Node6']}" would work, because the char vectors have the same length, but the other example is invalid Matlab syntax. Explaining code is meaningless, if the example input cause an error.
Please post meaningful inputs.
I do not understand, what this means:
"So I need to find the indicies for any input in A{1} again. One more example, if plotnumber = 9, it's indicies should be given automatically before the plot function."
@ Jan
'Let code look like code, and text like text. '
I already asked my real question and you only replied to it. But I tried your solution to get my intended result. But your solution didn't work.
Here is the link
What I need is, just plot name(Legend) along with the plot. You already gave the answer without telling how to give the index to the dispplayname. That is what I am looking for now. Index of either X{1} or X{2}. But those index should be taken automatically according to user input.
This is the user input
X = {[ 2 4 6] [ 'Node2'; 'Node4' ; 'Node6']};
@surendra kumar Aralapura mariyappa: The person who posted an answer in your other thread wa "Jon", but I am "Jan".
Unfortunately I do not understand, what you are asking for. "plot name(Legend) along with the plot." What does this mean?
How is this any different from your previous question for which you accepted my answer?
@ Jan & Guillaume
Thank you for all your kind responses.
I found the answer by myself. one of your colleague gave me the hint on the other day. Now I remembered that. Finaaly I did it.
'How is this any different from your previous question for which you accepted my answer?'
Th difference is I need the specific name Like X{2} = ['Air'; 'Oil';' Material']. But vector dimensions is not correct. I just need to know how to fix it!
Below was my code with the help of Bob.
@surendra kumar Aralapura mariyappa: X{2} = ['Air'; 'Oil';' Material'] is no valid Matlab syntax and this has been mentioned repeatedly already. You do not mention, what you want to achieve but repeat to post this strange piece of code. So how can we help you?
Maybe you want this instead:
X{1} = {'Air'; 'Oil';' Material'}
% ^ ^ Curly braces, not square brackets
Or
X{1} = ["Air"; "Oil";" Material"]
% ^ ^ ^ ^ ^ ^ double quotes for strings

Sign in to comment.

Answers (0)

Products

Release

R2014a

Community Treasure Hunt

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

Start Hunting!