Finding the indicies of the cell element
Show older comments
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
Stephen23
on 2 Jul 2019
"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.
surendra kumar Aralapura mariyappa
on 2 Jul 2019
Edited: surendra kumar Aralapura mariyappa
on 2 Jul 2019
Jan
on 2 Jul 2019
@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."
surendra kumar Aralapura mariyappa
on 2 Jul 2019
Jan
on 3 Jul 2019
@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?
Guillaume
on 3 Jul 2019
surendra kumar Aralapura mariyappa
on 4 Jul 2019
Jan
on 4 Jul 2019
@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
Answers (0)
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!