Plotting a simple line graph from cell array

6 views (last 30 days)
Greetings, I am trying to plot a 2D-line graph from the contents of a cell array but I am not able to achieve it. A simple code is attached as below and my objective is to plot a real-time graph of the x_value against counter. Thank you in advance for your help.
for i=1:5
x_value{i}=i+1
counter=i
end

Accepted Answer

Image Analyst
Image Analyst on 1 Sep 2012
If you can't avoid x_value being a cell array (instead of just a regular normal numerical array), then use cell2mat(). Try this:
counter = 1 : 5
for k = counter
x_value{k} = k + 1;
end
double_x = cell2mat(x_value)
plot(counter, double_x, 'bo-', 'LineWidth', 3, 'MarkerSize', 20);
grid on;
xlabel('counter', 'FontSize', 30);
ylabel('x value', 'FontSize', 30);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);

More Answers (0)

Categories

Find more on Line Plots 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!