Storing a surface slice in a .mat file and plotting the stored slice

Hi,
I use the slice function in matlab to slice through an echocardiopgrahic volume. As i create several slices from the volume, i want to increase the speed of my function. I want to create all the slices I want to plot (180 x 30ish slices) and store them somewhere (.mat or something simmilar). Then I want to be able to extract one of the slices and plot it. Here is what i want to do:
create several slices s,s1,s2....
s=slice(X,Y,Z,vol,X_1,Y_1,Z_1,'linear');
s1=slice(X,Y,Z,vol,X_2,Y_2,Z_2,'linear');
s2..
save(s,s1,s2....)
If i want to plot s2:
plot(s2)
I know that it will take some time to store all the slices, but then i omit to use the slice function everytime i want a new slice. I have experienced that the interp3 function is rather slow. I do not want to store them as a image, but i want the surface structure to be the same.
Is this possible?

 Accepted Answer

Why not just save the .fig files. See savefig(): https://www.mathworks.com/help/matlab/ref/savefig.html
Alternatively, you can also save fig handle in a .mat file, but that is not an recommended approach.
And if you really want to save the handle of slice objects in a .mat file then you can replot then as shown below
Save a slice object
s = slice(X,Y,Z,vol,X_1,Y_1,Z_1,'linear');
save('slices.mat', 's');
Then load them like this
data = load('slices.mat');
s = data.s;
ax = axes();
hold(ax);
view(3);
copyobj(s, ax);

4 Comments

Because I need to be able to extract geometrical points from the slices in the plot, when i re-plot them.
A .fig file preserves all the information that a slice object preserve (in reality, it save much more information). However, I have updated the answer to show how you can re-plot slices after loading them from a .mat file.

Sign in to comment.

More Answers (1)

You save all the slices into a cell and save them into .mat file.
S = cell(N,1) ;
S{1} = slice(X,Y,Z,vol,X_1,Y_1,Z_1,'linear');
S{2} = slice(X,Y,Z,vol,X_2,Y_2,Z_2,'linear');
Now you can save S alone which is a cell into a .mat file.

3 Comments

Thank you. What about plotting each slice? plot(S{1}) obiouvsly does not work, but I have not found a nice way to plot them after i store them.
You save the required X, Y, Z also,,,
Ok, but which function can i use to plot one specific surface? Something simmilar to plot3(X,Y,Z, s{1})?
If i use s=slice .. the slice is plotted. But when i store them, the s is only a surface structure. And i want to extract one surface and plot that surface from the .mat file.

Sign in to comment.

Categories

Products

Release

R2020a

Community Treasure Hunt

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

Start Hunting!