Can't get an output from my function using loops

function resultData = enter_data(numTrials)
dataArray = cell(numTrials, 4);
iteration = 1;
while iteration <= numTrials
promptName = "Enter the name of trial: ";
getName = input(promptName, 's');
dataArray{iteration, 1} = getName;
promptMeasure1 = 'Enter first measurement: ';
getMeasure1 = input(promptMeasure1);
dataArray{iteration, 2} = getMeasure1;
promptMeasure2 = 'Enter second measurement: ';
getMeasure2 = input(promptMeasure2);
dataArray{iteration, 3} = getMeasure2;
promptMeasure3 = 'Enter third measurement: ';
getMeasure3 = input(promptMeasure3);
dataArray{iteration, 4} = getMeasure3;
iteration = iteration+1;
end
disp(dataArray);
resultData = dataArray;
end
I'm unable to get resultData as an output from this function. What am I doing wrong?

2 件のコメント

Steven Lord
Steven Lord 2021 年 10 月 21 日
How are you calling the function? Please show us the exact call you made to enter_data.
Alec Burton
Alec Burton 2021 年 10 月 21 日
編集済み: Alec Burton 2021 年 10 月 21 日
I called it using enter_data(1) to test. That actually helped me, I didn't realize that I needed to include the output variable in the call. Thanks.

サインインしてコメントする。

 採用された回答

Alec Burton
Alec Burton 2021 年 10 月 21 日

0 投票

The problem I was having was related to the way I was calling the function. I hadn't realized I needed to include my output variable in the call because I had assumed I only needed to call the function name. My previous calls looked like: enter_data(1) when they should've looked like: resultData = enter_data(1)

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2021a

質問済み:

2021 年 10 月 21 日

回答済み:

2021 年 10 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by