필터 지우기
필터 지우기

sending 'result' as an input to a function

조회 수: 1 (최근 30일)
Muazma Ali
Muazma Ali 2021년 11월 21일
답변: Image Analyst 2021년 11월 21일
Hi!
I want to ask whether it is possible to send 'result ' clause as input to a function;
I have this code:
if antall_salter_tilgjengelige==3
S={'NH4Cl'; 'MgCl2'; 'CaCl2'; 'KCl'; 'ZnSO4'; 'NaCl'; 'ZnBr2'; 'CH3CO2K';'HCOOK';' HCOONa'; 'CaBr2'};
str={'Choose the salts available'};
result=listdlg('Promptstring',str, 'ListSize', [100,100], 'ListString', S, 'SelectionMode', 'multiple');
% everything that comes below here ,
% I want that segment to be a part of a function
% instead of having it at the same place as the code written above.
% The question is then whether I can send ''result'' as an input to a function...
if all(ismember(result,[1 2 3 ]))
forste_saltet=result(1,1);
andre_saltet=result(1,2);
tredje_saltet=result(1,3);

답변 (1개)

Image Analyst
Image Analyst 2021년 11월 21일
The answer is yes.
if antall_salter_tilgjengelige==3
S={'NH4Cl'; 'MgCl2'; 'CaCl2'; 'KCl'; 'ZnSO4'; 'NaCl'; 'ZnBr2'; 'CH3CO2K';'HCOOK';' HCOONa'; 'CaBr2'};
str={'Choose the salts available'};
result=listdlg('Promptstring',str, 'ListSize', [100,100], 'ListString', S, 'SelectionMode', 'multiple');
% everything that comes below here ,
% I want that segment to be a part of a function
% instead of having it at the same place as the code written above.
% The question is then whether I can send ''result'' as an input to a function...
otherResults = myFunction(result)
end
%=======================================================================================
function otherResult = myFunction(result)
otherResult 0; % Whatever you want to return...
if all(ismember(result,[1 2 3 ]))
forste_saltet=result(1,1);
andre_saltet=result(1,2);
tredje_saltet=result(1,3);
end

카테고리

Help CenterFile Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by