How to display rectangle ROI that was loaded from a file?

1 次查看(过去 30 天)
To be able to save and share figures for my app, I save user-drawn rectangles in a rectangle array and write that to a .mat file. Another user at a later time can import that rectangle array to display on a figure. I have the rectangle array imported properly to matlab, but how can I draw the rectangles from the rectangle array objects rather than the drawrectangle() function? Essentially, I want "drawrectanglefromfile" or "displayrect"
Thanks!

采纳的回答

Voss
Voss 2024-3-1
You can set the saved rectangles' parent to be a different/new axes.
Example:
% plot some rectangles:
xlim([0 1])
ylim([0 1])
R = [ ...
rectangle('EdgeColor',[0 0.6 0 ],'Position',[0.2 0.1 0.7 0.6]) ...
rectangle('EdgeColor',[0 0.2 0.8],'Position',[0.1 0.2 0.6 0.7]) ...
];
% save the rectangles to a mat file:
save('R.mat','R')
% load the mat file:
S = load('R.mat')
S = struct with fields:
R: [1×2 Rectangle]
% put the loaded rectangles in a new axes in a new figure:
figure
ax = gca();
set(S.R,'Parent',ax);
  2 个评论
Alex
Alex 2024-3-1
Thanks again! :) You are the same person that helped me yesterday with the table editing
Do you know how I can write the parent for each object in the rectangle array in one line? I assume there has to be a better way than this, but the for loop below works:
for i=1:length(app.ROI_array)
app.ROI_array(i).Parent = app.VisualModel;
end
I get an error when I try to write it like this:
app.ROI_array(:).Parent = app.VisualModel;
Voss
Voss 2024-3-1
编辑:Voss 2024-3-1
You're welcome!
Use the set function:
set(app.ROI_array,'Parent',app.VisualModel)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by