How to update multiple graphs from one plot in one statement in Matlab? -
i have this:
p = plot([0 1], [0 1], [1 2], [1 2]);
i want take each pair , append number.
x = get(p, 'xdata'); y = get(p, 'ydata'); x1 = mat2cell([x{1} double(2)]); y1 = mat2cell([y{1} double(2)]); x2 = mat2cell([x{2} double(3)]); y2 = mat2cell([y{2} double(3)]); set(p, 'xdata', [x1; x2], 'ydata', [y1; y2]); % not work drawnow;
'get' giving me data in format , 'set'-ing in same format data 1 more value each pair.
the error is: conversion double cell not possible.
there number of different ways fetch current plot points , add them. first 2 lines of eitan's answer (using cellfun
) 1 way. here's 1 using cell2mat
, num2cell
:
newx = [2 3]; % new x values add newy = [2 3]; % new y values add x = num2cell([cell2mat(get(p,'xdata')) newx(:)], 2); y = num2cell([cell2mat(get(p,'ydata')) newy(:)], 2);
the key issue note when using set
function on multiple handles stated in excerpt documentation:
set(h,pn,mxn_pv) sets n property values on each of m graphics objects, m = length(h) , n equal number of property names contained in cell array pn. allows set given group of properties different values on each object.
as result, single call set
has this:
set(p, {'xdata'}, x, {'ydata'}, y);
note length(p)
equal 2, property strings placed in cell arrays, , x
, y
each 2-by-1 cell arrays.
Comments
Post a Comment