sending 'result' as an input to a function

1 次查看(过去 30 天)
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