Represent the figures on the XZ (or YZ) plane

7 views (last 30 days)
Hi! I would like to modify my code so that the figures are shown on the XZ (or YZ) plane and not on the XY plane (as in my code).
How can I modify it?
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
myFolder = 'C:\Users\...';
filePattern = fullfile(myFolder, '*.png');
imageFiles = dir(filePattern);
hFig3 = figure('Name', '3D Plot', 'NumberTitle', 'off');
% z-coordinates to use:
z = 1+100*(0:numel(imageFiles)-1); %[1 101 201 ...]
for k = 1:length(imageFiles)
baseFileName = imageFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
drawnow;
% Call pic2points. This will open a new figure.
CoordinateMatrix = pic2points(imageArray);
% Switch to the figure for the 3-D plotting:
figure(hFig3);
% scatter(CoordinateMatrix(:, 1), CoordinateMatrix(:, 2), '.');
current_z = z(k) * ones(size(CoordinateMatrix, 1), 1);
plot3(CoordinateMatrix(:, 1), CoordinateMatrix(:, 2), current_z, '.');
hold on
drawnow;
end
grid on;
hFig3.WindowState = 'maximized';
fprintf('Done running %s.m.\n', mfilename);
xlabel('axis X')
ylabel('axis Y')
zlabel('axis Z')

Accepted Answer

Voss
Voss on 2 Nov 2022
XY plane (current):
plot3(CoordinateMatrix(:, 1), CoordinateMatrix(:, 2), current_z, '.');
XZ plane:
plot3(CoordinateMatrix(:, 1), current_z, CoordinateMatrix(:, 2), '.');
% or
plot3(CoordinateMatrix(:, 2), current_z, CoordinateMatrix(:, 1), '.');
YZ plane:
plot3(current_z, CoordinateMatrix(:, 1), CoordinateMatrix(:, 2), '.');
% or
plot3(current_z, CoordinateMatrix(:, 2), CoordinateMatrix(:, 1), '.');

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!