필터 지우기
필터 지우기

Hi there, I'm encountering an issue and would appreciate your guidance in resolving it.

조회 수: 2 (최근 30일)
  댓글 수: 1
Dyuman Joshi
Dyuman Joshi 2023년 10월 7일
What if mode is not equal to " Boost " or " Buck "? What should be the value of the variables in that case?
You can either define the values or give an error message.

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

채택된 답변

Image Analyst
Image Analyst 2023년 10월 7일
mode is a built-in function. Don't use it as the name of your variable!!
Also, you need to initialize your variables before the if block in case neither of your conditions is met.
function [q1, q2, q3, q4] = ConverterControl(modeString, D)
q1 = nan;
q2 = nan;
q3 = nan;
q4 = nan;
% Trim off white space
modeString = strtrim(modeString);
if strcmpi(modeString, 'Boost') % Don't use spaces around Boost anymore. It's more robust this way.
%etc.
Or you could use contains with IgnoreCase=true if you're certain you'll never have Boost and Buck in the same modeString, and then if you use contains() you could eliminate strtrim().

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by