Receiving error when trying to obtain multiple inputs
이전 댓글 표시
I have three user inputs with three prompts before hand. I am trying to have the code ask a question, user inputs, assigns string input to a variable, and have that do it three times (once for each prompt). Although after entering a value for the first prompt, the code returns an issue with the second prompt. I am not sure what the issue is. Can someone help me out?
I have included the entire code, I am aware that the "if" statements are reptitive and could be optimized.
Below is the code for reference:
%Assuming using Glass FRP rated at 480 Mpa (Range: 480-1600 Mpa)
%Defining Variables (in MPA):
plastic_tensile = 23.00001401;
frp_tensile = 479.9999027;
%Recieve user inputs for material chosen, atmospheric pressure, and radius of opening:
prompt1 = ("Please enter the material you would like to test (a. plastic b. frp): ");
prompt2 = ("Input the atmospheric pressure you would like to test (in PSI): ");
prompt3 = ("Input the radius of the opening you would like to calculate (in meters): ");
picked_mat = input(prompt1, 's');
psi = input(prompt2, 's');
r = input(prompt3, 's');
pimatlwr = lower(picked_mat);
%Calculate response based on info
% F = P*A
%oparea meaning (Area of Opening)
if pimatlwr {"plastic"}
oparea = (pi * (r^2));
newtons = (psi * oparea);
nm2 = (newtons/oparea);
mpaarea = (nm2/1000000);
dataset1 = [mpaarea];
reply1 = ("The area of the opening would exert %2.0f on the sheet. The sheet can only withstand 23 MPA, thus it would break.");
reply2 = ("The area of the opening would exert %2.0f on the sheet. The sheet can withstand 23 MPA, thus it would not break.");
if mpaarea > plastic_tensile
text = fprintf(reply1, dataset1);
elseif mpaarea < plastic_tensile
text2 = fpritnf(reply2, dataset1);
end
end
if pimatlwr {"frp"}
oparea = (pi * (r^2));
newtons = (psi * oparea);
nm2 = (newtons/oparea);
mpaarea2 = (nm2/1000000);
dataset2 = [mpaarea];
reply1_1 = ("The area of the opening would exert %2.0f on the sheet. The sheet can only withstand 480 MPA, thus it would break.");
reply2_1 = ("The area of the opening would exert %2.0f on the sheet. The sheet can withstand 480 MPA, thus it would not break.");
if mpaarea > frp_tensile
text1_1 = fprintf(reply1_1, dataset2);
elseif mpaarea < plastic_tensile
text2_1 = fpritnf(reply2_1, dataset2);
end
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!