looping thru multiple line data in UIAxes plot and writing all X,Y data to an array
10 次查看(过去 30 天)
显示 更早的评论
Hello, i have a set of line plots on a UIAxes on a UIFigure using Appdesigner.
Note each plot has differing X coordinates
I want a way to be able to save all these plots so that I can revisit later and add further plots to it.
The approach I was going to take was to access the line objects and loop through assigning each X,Y datat set to a data array that I could save out and then recal at a later date.
ax=app.UIAxes;
L=ax.XLim;
L2=L(2); % Get max number on x-axis
h1 = findall(ax, 'type', 'line') % Get just line objects for now
n=numel(h1); % Number of line plots (will do text objectes later)
H=nan(L2,2*n) % Create an array of Nans to hold all data (row,cols)
% Each line requires its X data to be saved also
Now loop thru' all line items and splat the X,Y data to the array
for(i=1:n)
t = h1(i)
H(:,(2*i)-1)=(t.XData)';
H(:,2*i)=(t.YData)';
end
H
But Im getting the following error
Unable to perform assignment because the size of the left side is 120-by-1 and the size of the right side is 100-by-1.
Error in GenericDataAnalysis/ReadHeadersButtonPushed (line 533)
H(:,(2*i)-1)=(t.XData)';
I suspect its to do with non-equal length of data sets. Perhaps I need some sort of padding for the missing data?
This is my current output:
L2 =
120
h1 =
7×1 Line array:
Line (20s Delay)
Line (15s Delay)
Line (9s Delay)
Line (5s Delay)
Line (2s Delay)
Line (FC Top)
Line (FC Btm)
The second part of my question, is whats the best approach to retain the colours and text objects?
Remember, i don't just want the graphic saved, I want to be able to add data to it later from within my GUI.
Thanks
Jason
0 个评论
回答(1 个)
Rik
2024-6-11
I would suggest a struct array. That way you can store all relevant properties and you can fairly easy recreate the line objects.
3 个评论
Rik
2024-6-11
You're fairly close, but the errors are why I suggested using a struct array instead of an object array. Each object contains information about the parent object as well. that means you can only save and restore your current objectes, which isn't the goal.
By using a struct you can store all the properties you need to reconstruct the objects from scratch.
Don't be afraid of a for loop, they are very fast in Matlab.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!