필터 지우기
필터 지우기

how to enter values to array using loop

조회 수: 5 (최근 30일)
tomer polsky
tomer polsky 2017년 3월 17일
답변: aisha 2023년 10월 17일
hello , I want to make a loop for exmpale from 1:1:100 and then enter each number into an array of each number of array . for exmpale my program is :
clc;
clear all;
k=1;
DC=input('enter DC:');
for DC=DC:1:100
disp(DC)
end
if(k==1)
arr=zeros(100,9);
end
if (k>0 && k<100)
arr(k)=DC;
end
when I run this script only the last value saves in the array . how can i save all the values of the loops ?

채택된 답변

KSSV
KSSV 2017년 3월 17일
Simply use:
iwant = 1:100 ;
or
N = 100 ;
iwant = zeros(1,N) ;
for i = 1:N
iwant(i) = i ;
end
  댓글 수: 1
tomer polsky
tomer polsky 2017년 3월 17일
thank u helped me ,I changed the code but u gave me the idea how to change it ,anyway thank u very much !

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

추가 답변 (2개)

Adam
Adam 2017년 3월 17일
편집: Adam 2017년 3월 17일
DC = zeros(1,100);
for n = 1:numel( DC )
DC(n) = input(...)
end
That's a guess at what you are trying to do, it isn't obvious what you are aiming for though.

aisha
aisha 2023년 10월 17일
for j=1:N
for i=j+1:N
L(i,j)=(A(i,j)-L(i,j-1)*U(j-1,j))/U(j,j)
U(j,j)=A(j,j)-sum(L(j,1:j-1)*U(1:j-1,j));
U(j,j+1)=A(j,j+1)-L(j,j-1)*U(j-1,j+1);
end
for k=i+1:N
L(k,j)=(A(k,j)-L(k,k-1)*U(k-1,j))/U(j,j);
end
end
me unable to find error. can anyone help in using loop

카테고리

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