Empty plot returning when I try to graph

4 ビュー (過去 30 日間)
Natali Petani
Natali Petani 2022 年 12 月 1 日
編集済み: Kevin Holly 2022 年 12 月 1 日
funciton code
function G = sigmayytheta0(rr) %why did we even need sigma_0 in the first place..?
K = 0.5605;
G = (K/sqrt(2*pi*rr)); %when theta = 0, everything including theta simplifies to 1
end
script code
%sigmayy along theta = 0 degrees
for i = 1:1000;
for j = 1:1000;
x = i/1000;
y = (j-500)/1000;
xtip = x - .1;
rr = sqrt(xtip^2+(y^2));
M = sigmayytheta0(rr);
hold on
end
end
figure(2)
plot(rr,M, "--");
hold off
xlabel('r')
ylabel('sigmayy')
title('Sigmayy versus r at theta = 0');

回答 (3 件)

Kevin Holly
Kevin Holly 2022 年 12 月 1 日
編集済み: Kevin Holly 2022 年 12 月 1 日
%sigmayy along theta = 0 degrees
for ii = 1:10;
for jj = 1:10;
x = ii/1000;
y = (jj-500)/1000;
xtip = x - .1;
rr(ii,jj,:) = sqrt(xtip^2+(y^2));
M(ii,jj) = sigmayytheta0(rr(ii,jj));
figure(1)
scatter(rr(ii,jj),M(ii,jj),'.b');
hold on
end
end
hold off
xlabel('r')
ylabel('sigmayy')
title('Sigmayy versus r at theta = 0');
figure(2)
plot(rr,M, "--");
% hold off - remove this hold off
xlabel('r')
ylabel('sigmayy')
title('Sigmayy versus r at theta = 0');
function G = sigmayytheta0(rr) %why did we even need sigma_0 in the first place..?
K = 0.5605;
G = (K/sqrt(2*pi*rr)); %when theta = 0, everything including theta simplifies to 1
end

Walter Roberson
Walter Roberson 2022 年 12 月 1 日
M = sigmayytheta0(rr);
Every iteration in i and j, you are overwriting all of M. At the end, your M will be a scalar.
You should be storing into something indexed with i and j. Likewise with rr
plot(rr,M, "--");
If you assign to rr and M indexed by i and j, you are going to end up with a 2D array, but plot() is for drawing lines. Do you want to draw a scatter plot? Perhaps you want to draw a contour plot? Or a surface plot?
Note that there will be a number of different locations that come out to the same rr value. You are calculating a radius from i = 10, j = 500 and that is going to be radially symmetric.

David Hill
David Hill 2022 年 12 月 1 日
[i,j]=meshgrid(1:1000);
xtip=i/1000-.1;
y=(j-500)/1000;
rr=hypot(xtip,y);
K=.5605;
M=K./(sqrt(2*pi*rr));
plot(rr,M, "--");
xlabel('r')
ylabel('sigmayy')
title('Sigmayy versus r at theta = 0');

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by