Regarding 'Or' condition in if statement., this code is running in Octave but not in Matlab. Could anyone help, how to make it work in Matlab. This is just an eg.

조회 수: 8 (최근 30일)
clear all;
close all;
clc;
Question = input('Would you like to continue, [Y/N] \n','s')
if (Question=='Y') || (Question=='y')
a= 2*2
elseif (Question=='N') || (Question=='n')
b=3*3
end
  댓글 수: 1
jessupj
jessupj 2021년 9월 15일
maybe:
if ( (Question=='Y') || (Question=='y') )
...
you didn't indicate what the error was. ie is it a problem with the double-bar or vs single-bar, or one with the if statment check.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2021년 9월 15일
It works perfectly fine, though in MATLAB we'd do it like this:
clear all;
close all;
clc;
Question = input('Would you like to continue [Y or N]?\n', 's')
if strcmpi(Question(1), 'Y')
a = 2 * 2
else
b = 3 * 3
end

카테고리

Help CenterFile Exchange에서 Scripts에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by