필터 지우기
필터 지우기

How add another loop in program

조회 수: 1 (최근 30일)
hasan s
hasan s 2021년 3월 18일
편집: Jan 2021년 3월 22일
Hi
First of all, thanks to all the experts who help others...I appreciate your time, And best wishes to everyone.
I have program ( take column1 column2 until column100 , to get 100 a and 100 b and 100 c)and I need to get the following...which print it as follows ,and I dont know where I add it in the same program since it depend on the output of it (that get 100 values of a ,b,c ).where A,B, C are the intial values.
c2=0;
for w=1:100
c2=c2+1;
value1=value1+(((a(w))-A)^2)\100; %a(w) is 100 value of a
value2=value2+(((b(w))-B)^2)\100; %b(w) is 100 value of b
value3=value3+(((c(w))-C)^2)\100; %c(w) is 100 value of c
end
value1;
value2;
value3;
and, (if possible) to add to the program" if else "for the error (or "while " of "if" as you show correct in my program)
if any Prof. can help me thanks alot.
  댓글 수: 2
hasan s
hasan s 2021년 3월 18일
편집: hasan s 2021년 3월 18일
I donot know how I get the values of a,b,c that obtained inside every loop .
and put it as 100 values in the output as a 100 column to save it all ,, what I change in the program..please
Jan
Jan 2021년 3월 19일
I do not exactly understand, what you want to change.

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

채택된 답변

Jan
Jan 2021년 3월 19일
The only problems I see is that value1/2/3 is not initialized and that the division is /, not \ .
c2 is not used, so omit it.
value1 = 0;
value2 = 0;
value3 = 0;
for w = 1:100
value1 = value1 + (a(w) - A)^2 / 100;
value2 = value2 + (b(w) - B)^2 / 100;
value3 = value3 + (c(w) - C)^2 / 100;
end
value1
value2
value3
Or vectorized as typical Matlab code:
value1 = sum((a - A)^2) / 100;
value2 = sum((b - B)^2) / 100;
value3 = sum((c - C)^2) / 100;
  댓글 수: 14
Jan
Jan 2021년 3월 20일
편집: Jan 2021년 3월 22일
I had some mistakes in my suggested code: the elementwise operations .* and .^ are required.
Make the result repeat 100 times and each time contains 100 numbers ?
No, this pre-allocation let a,b,c be vectors of size [1, 100].
hasan s
hasan s 2021년 3월 20일
편집: hasan s 2021년 3월 21일
Prof Jan...
Iam sorry ....the repeat of program alot of times due to damage of matlab in my laptop.
Now it is running correctly.
thank you very very much for your help

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by