looping thru multiple line data in UIAxes plot and writing all X,Y data to an array

조회 수: 3 (최근 30일)
Jason
Jason 2024년 6월 10일
댓글: Jason 2024년 6월 11일
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

답변 (1개)

Rik
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
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.
Jason
Jason 2024년 6월 11일
Hi, when I tried this, I created a field in the Struct where I assign the complete line objects to the struct.
But then when I tried to save this out in a mat file, it complained it couldnt save the objects.
h1 = findall(ax, 'type', 'line') % Line objects
datastruct.Lines=h1;
thats why I switched to usign "variables" instead

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

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by