Axis limits not working

33 ビュー (過去 30 日間)
Mark Conway
Mark Conway 2021 年 4 月 21 日
コメント済み: Mark Conway 2021 年 4 月 21 日
Hi,
I'm trying to get Matlab to plot a Riemann sum using scatterbar3. I want the x axis to go from -2 to 2 but no matter what I try Matlab will not let me scale the xaxis from -2 to 2. I've tried xlim, ylim, axis manual etc but nothing seems to work.This means the graph displays rectangular Riemann bars instead of square ones. The output I get is below:
The code I've done so far is below (I'll add more Riemann bars once I've gotten this issue sorted). If anyone knows how to fix this that would be great!
%% Riemann sums for double integration
clc;
close all;
clear;
m = 20; %Number of increments for riemann sum
a = -2; %Lower limit of integration for square domain
b = 2; %Upper limit of integration for square domain
figure
hold on
xlabel('x')
ylabel('y')
h = (b-a)/m; %increment length
x = a+h/2:h:b-h/2; %mid-point of m increments of x
y = a+h/2:h:b-h/2; %mid-point of m increments of y
mymap = [1 0 0];
colormap(mymap)
axis([-2 2 -2 2]);
axis manual
for k=1:length(x)
xforloop = zeros(1,length(x))+x(k);
zforloop = 9-xforloop.^2 - y.^2;
end
scatterbar3(xforloop, y, zforloop,h );
hold off
  1 件のコメント
Mark Conway
Mark Conway 2021 年 4 月 21 日
Well that was embarassing - I just had to add the axis command after the scatterbar3 function command - I guess Matlab must just look for the axis commands straight after the plot command.

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2021 年 4 月 21 日
xlim, ylim, zlim should have worked.
You need to set them after you plot the scatterbar3.
  1 件のコメント
Mark Conway
Mark Conway 2021 年 4 月 21 日
Thanks Adam. Your right - that fixed it.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by