How do i save values for each iteration ?

조회 수: 1 (최근 30일)
Lauris Cuzans
Lauris Cuzans 2021년 4월 16일
답변: David Hill 2021년 4월 16일
clc
clear
for a = [0.01 0.01 0.01 0.03 0.1 0.2 0.3 0.3 0.3 0.4 0.4 0.4 0.3 0.4 0.5 0.8 0.9 1 0.8 0.7 0.5 0.2 0.1 0.03];
b=a*5
end
How can I store new values of b for each iteration ?
  댓글 수: 1
Mischa Kim
Mischa Kim 2021년 4월 16일
Hi Lauris, depends. What exactly are you trying to do?

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

채택된 답변

David Hill
David Hill 2021년 4월 16일
a = [0.01 0.01 0.01 0.03 0.1 0.2 0.3 0.3 0.3 0.4 0.4 0.4 0.3 0.4 0.5 0.8 0.9 1 0.8 0.7 0.5 0.2 0.1 0.03];
for k= 1:length(a)
b(k)=a(k)*5;%index into b
end
Better, just multiply, no loop needed.
b=5*a;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by