matlab如何将每次循环的结果输出?
时间: 2023-07-18 11:12:17 浏览: 656
matlab怎么输入输出
在 MATLAB 中,你可以通过在循环中使用 disp 函数来输出每次循环的结果。以下是一个示例代码:
```
for i = 1:10
result = i^2;
disp(['The result of iteration ', num2str(i), ' is ', num2str(result)]);
end
```
这段代码将输出每次迭代的结果,例如:
```
The result of iteration 1 is 1
The result of iteration 2 is 4
The result of iteration 3 is 9
The result of iteration 4 is 16
The result of iteration 5 is 25
The result of iteration 6 is 36
The result of iteration 7 is 49
The result of iteration 8 is 64
The result of iteration 9 is 81
The result of iteration 10 is 100
```
阅读全文