Assigning positions to multiple figures along-z-axis.
Show older comments
hi,
I have a code that generates multiple contour filled plots using a for loop. i want to position the each result at different positions along the z-axis as when i am running the code, it overwrites the previous image and not able to change the position along-z-axis. here is the code. I have tried hold function but how can i hold the plots one on top of the other. As i want multiple 2D contour plots in one matlab figure seperated by distance along the z-axis.
Or if there is a way to access already saved contourfilled plots and plotting them on top of other.
Code:
figure(1);
for i=1:1:7
hold on
slice= MAG_uwb_scatt_incoh_reconstr_diff_OLD_normalised(:,:,i);
x=X_reconstr(:,:,i);
y=Y_reconstr(:,:,i);
limit=[0.6 1];
contourf(x,y,slice,'LineStyle' , 'none');
view(3)
caxis(limit)
colorbar
grid on
axis normal
end
using this code i am getting this result.

but instead of this i want results like this and i want to position them along -zaxis. Yours help will be greatly appreciated, i would be greatfull if you suggest me solution to this. thanks.

Accepted Answer
More Answers (1)
Image Analyst
on 29 Sep 2021
You can probably adapt this code:
% Takes an RGB image and stacks the separate color channels at different Z levels.
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 13;
filename = 'peppers.png';
rgbImage = imread(filename);
% Extract the individual red, green, and blue color channels.
redChannel = im2double(rgbImage(:, :, 1));
greenChannel = im2double(rgbImage(:, :, 2));
blueChannel = im2double(rgbImage(:, :, 3));
H(1) = slice(repmat(redChannel,[1 1 2]),[],[], 1); %slice() requires at least 2x2x2
set(H(1),'EdgeColor','none') %required so image isn't just an edge
hold on
H(2) = slice(repmat(greenChannel,[1 1 2]),[],[], 2); %slice() requires at least 2x2x2
set(H(2),'EdgeColor','none') %required so image isn't just an edge
H(3) = slice(repmat(blueChannel,[1 1 3]),[],[], 3); %slice() requires at least 2x2x2
set(H(3),'EdgeColor','none') %required so image isn't just an edge
hold off
colormap(gray(256))
axis ij
caption = sprintf('R, G, and B Color Channels of %s', filename);
title(caption, 'FontSize', fontSize);
% Put up legend that says what slice is what color channel.
legend('B', 'G', 'R')

Categories
Find more on Display 2-D Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!