Let’s say I have 11 values of beta, evenly-spaced with linspace( ). And let’s say for each value of beta, I want to compute some things for a range of alpha values using alpha = linspace( ). How can I best do this? Currently, I do something tedious: I fix beta, run the code, press hold on in the Command Window, fix another value of beta, run code, press hold on, etc. I suspect there’s a better way to do this. Should I just write a for loop for beta = 0: 11 : pi? Thanks in advance.

 채택된 답변

Torsten
Torsten 2024년 10월 4일
이동: Torsten 2024년 10월 4일

0 개 추천

Beta = linspace(0,1,10);
Alpha = linspace(0,2,20);
n = numel(Beta);
m = numel(Alpha);
Result = zeros(n,m);
for i = 1:n
beta = Beta(i);
for j = 1:m
alpha = Alpha(j);
Result(i,j) = alpha*beta; % Compute result depending on actual alpha and beta
end
end

댓글 수: 2

Noob
Noob 2024년 10월 4일
Hi Torsten!
Let me try this now -- thanks for your answer!
Noob
Noob 2024년 10월 21일
Thanks Torsten!

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

태그

질문:

2024년 10월 4일

댓글:

2024년 10월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by