Unable to plot graphs

2 ビュー (過去 30 日間)
Abdullah Hassan
Abdullah Hassan 2021 年 11 月 7 日
コメント済み: Abdullah Hassan 2021 年 11 月 10 日
%S-N Graph Plot for Fatigue Testing for the three specimens
%Defined Parameters
disp('The dimensions and parameters of the Test:');
disp('The diameter for each of the specimen, D=5mm');
disp('The distance from the end of the specimen and the minimum diameter of the specimen, L = 78mm');
D = 5; L = 78; N=5;
%The weight that are loaded (kg) are then later converted to Newton (N)
disp('The weight in Newton (N) applied on each of the specimen');
P = [7.580811,9.02244,10.38561,13.20022,14.63204];
disp('Using the Defined Parameters for all the value of (P), the stress is calculated using the formula of stress');
S = [240.8874,286.6965,330.0126,419.4494,464.9469];
%Determining the Number of Cycles done by the three Specimens
disp('The number of cycles done with stress applied and number of trials for Mild Steel');
for f = 1:N
Ms(f)=input(['Load Number:'num2str(f)','Cycles done:']);
f=f+1;
end
disp('The number of cycles done with stress applied of trials for Aluminium');
for d = 1:N
Ali(d)=input(['Load Number:'num2str(d)',Cycles Done:']);
d = d+1;
end
disp('The number of cycles done with stress applied and number of trials for Brass');
for g = 1:N-1
Brs(g)=input(['Load Number:'num2str(g)',Cycles Done: ']);
g = g+1;
end
%Arranging allt he values
disp('The Number Of Cycles taken by Aluminium');
disp(Ali);
disp('The Number Of Cycles taken by Mild Steel');
disp(Ms);
disp('The Number of Cycles taken by Brass');
disp(Brs);
%Plotting the S-N Curve for the three Specimens
%For Aluminium
figure
plot (Ali,S)
title('S-N graph (ALuminium)')
xlabel('Number of Cycles (N)')
ylabel('Stress Applied (N/mm^2)')

採用された回答

Jan
Jan 2021 年 11 月 7 日
編集済み: Jan 2021 年 11 月 7 日
for f = 1:N
Ms(f)=input(['Load Number:'num2str(f)','Cycles done:']);
f=f+1;
end
This is not the way for loops work in Matlab. Omit the line f=f+1, because it does not do anything useful here. The loop counter is increased by the for command already:
for k = 1:5
disp(k)
end
I've formatted the code in your question (please do this by your own in following questions). Immediately you can see a problem with the syntax:
Ali(d)=input(['Load Number:'num2str(d)',Cycles Done:']);
The syntax highlighting shows you, that the right string is not properly enclosed in quotes. The quote directly behind a variable or closing parenthesis or square bracket is interpreted as transposition (to be exact: as conjugate transposition). Prefer to separate parts of concatenations by commas to increase the clarity:
Ali(d)=input(['Load Number:', num2str(d), 'Cycles Done:']);
I'd prefer:
Ali(d) = input(sprintf('Load Number: %d Cycles Done:', d));
If the code has such a syntax error, it does not run at all, but trying to start it produces an error message. Then the description "unable to plot graphs" does not hit the point.
  1 件のコメント
Abdullah Hassan
Abdullah Hassan 2021 年 11 月 10 日
thank u very much

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

その他の回答 (0 件)

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by