Error is coming how can I solve?

Cell contents reference from a non-cell array object.
Error in Mineral_2 (line 12)
line([A(xmaxA) A(xmaxA)], [limh(1) max(A(:,2))], 'color', chrom{1},'Linestyle',':')

Answers (3)

Caroline
Caroline on 23 Aug 2013
Could you post the code? It could be because you used {} instead of () to access the element of an array but its hard to say without seeing the code.

1 Comment

RS
RS on 23 Aug 2013
Edited: RS on 23 Aug 2013
h=plot(A(:,1),A(:,2));
ymaxA=max(A(:,2));
xmaxA=find(A(:,2)==max(A(:,2)));
xA0=A(A(:,2)==0);
limh=get(gca,'Ylim');
chrom=get(h,'color');
line([A(xmaxA) A(xmaxA)], [limh(1) max(A(:,2))], 'color', chrom(1),'Linestyle',':');
again some error are coming here how can I improve?
Image Analyst
Image Analyst on 23 Aug 2013
Edited: Image Analyst on 23 Aug 2013
Before that line, put these lines:
whos chrom
chrom{1}
Tell us what it says. Then look at this link: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
Walter Roberson
Walter Roberson on 23 Aug 2013
You make chrom a cell array. Somehow it is not one at the moment in your code.

5 Comments

h=plot(A(:,1),A(:,2));
ymaxA=max(A(:,2));
xmaxA=find(A(:,2)==max(A(:,2)));
xA0=A(A(:,2)==0);
limh=get(gca,'Ylim');
chrom=get(h,'color');
line([A(xmaxA) A(xmaxA)], [limh(1) max(A(:,2))], 'color', chrom(1),'Linestyle',':');
some error are coming here how can I improve?
plot() of a single column will return the handle of a single lineseries object. You get() the color property of that one object, and what will be returned will be a string rather than a cell array of strings. So just pass chrom into line() rather than passing chrom{1} or chrom(1)
A=[];
A(:,1)=B(:,1);
A(:,2)=B(:,2);
figure;
h=plot(A(:,1),A(:,2));
ymaxA=max(A(:,2));
xmaxA=find(A(:,2)==max(A(:,2)));
xA0=A(A(:,2)==0);
limh=get(gca,'Ylim');
chrom=get(h,'color');
line([A(xmaxA) A(xmaxA)], [limh(1) max(A(:,2))], chrom,'Linestyle',':');
Vectors must be the same lengths. This error is coming when I am using this
line([A(xmaxA) A(xmaxA)], [limh(1) max(A(:,2))], chrom,'Linestyle',':');
How can I solve?
You need to have the same number of x values as y values, and you need, need, need to learn basic debugging skills. Is B an integer array, so that you might have multiple locations for xmaxA? What can you learn from doing this:
xValues = [A(xmaxA) A(xmaxA)]
size(xValues)
yValues = [limh(1) max(A(:,2))]
size(yValues)
You still need the keyword 'color'
line([A(xmaxA) A(xmaxA)], [limh(1) max(A(:,2))], 'color', chrom,'Linestyle',':');

This question is closed.

Asked:

RS
on 23 Aug 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!