Plotting a cell array with double values

Hello,
I am very new to Matlab and searched a lot to find a solution to the problem I am facing but, somehow I have not been able to.
I have an array which looks something like - test1 = 0.3; test2 = 0.4; test3 = 0.5; test4 = 0.2;
testArray = {test1, test2, test3, test4}
I would like to plot this with y-axis having a scale from say 0-1 and, x-axis having values test1, test2, test3, test4 and the actual plotted values on the graph being the values of these variables (0.3, 0.4, 0.5, 0.2).
Is this possible in Matlab? If yes how? And if not, can I at least have something which is close this kind of display? If I just try to plot testArray by using plot(testArray), I get an error -
??? Error using ==> plot Conversion to double from cell is not possible.
which I am guessing is not too hard to solve but that is only a backup display which I would like if, there is not better way to display what I want.
Thank you.

 채택된 답변

Walter Roberson
Walter Roberson 2011년 8월 30일

1 개 추천

Use
testArray = [test1, test2, test3, test4]
and the problem will go away.
plot(1:4, testArray, 'XTick', 1:4, 'XTickLabel', {'test1', 'test2', 'test3', 'test4'})
I wonder, though, whether you would perhaps prefer to use bar() instead of plot() ?

댓글 수: 3

Apar
Apar 2011년 8월 30일
Thank you for the prompt reply.
I tried what you suggested and I think I should be able to figure it out from there because I wasn't sure about the properties set on the plot. I get the following error -
>> plot(1:4, testArray, 'XTick', 1:4, 'XTickLabel', {'test1', 'test2', 'test3', 'test4'})
??? Error using ==> plot
Invalid property found.
Object Name : line
Property Name : 'XTick'.
I think bar might be a better idea as you suggested :) but, right now I just need some kind of visualization!
Apar
Apar 2011년 8월 30일
Instead of using -
plot(1:4, testArray, 'XTick', 1:4, 'XTickLabel', {'test1', 'test2', 'test3', 'test4'})
as you suggested. I did the following and it worked.
plot(testArray)
set(gca, 'XTickLabel', {'test1', 'test2', 'test3', 'test4'})
Thank you!
Elias Salilih
Elias Salilih 2023년 8월 7일
What about plotting cell vs double using double axis plot (i.e., plotyy)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Yoav Livneh
Yoav Livneh 2011년 8월 30일

2 개 추천

Use
testArray = [testArray{:}];
This will transform testArray into a regular array which you can plot using
plot(testArray)

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

질문:

2011년 8월 30일

댓글:

2023년 8월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by