필터 지우기
필터 지우기

Hi, Can someone help me with this?

조회 수: 1 (최근 30일)
syed shamsi
syed shamsi 2014년 3월 19일
답변: Shivani Dixit 2021년 5월 25일
z=x/ length
length=100
x=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
Create empty vector for z. Use for loop to calculate the z for all the data pairs
  댓글 수: 1
Walter Roberson
Walter Roberson 2014년 3월 20일
It is not recommended to name a variable "length" as that conflicts with the frequently-used MATLAB function length()

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

답변 (1개)

Shivani Dixit
Shivani Dixit 2021년 5월 25일
The above issue can be solved in following methods:
  1. When you could create an empty vector for z (as mentioned above), you can keep on reassigning z its previous value plus the new value you get in every iteration from for loop. You can see the code below for more information.
>> x=1:16;
>> length=100;
>> z=[];
>> for a=1:16
z=[z a/length];
end
>> z
z =
Columns 1 through 10
0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700 0.0800 0.0900 0.1000
Columns 11 through 16
0.1100 0.1200 0.1300 0.1400 0.1500 0.1600
  1. You can also try to simply divide the vector "x" by a desired value and assign it to z. (If this is permitted). This will give you a lesser complex solution.
>> x=1:16;
>> length=100;
>> z=x/length
z =
Columns 1 through 10
0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700 0.0800 0.0900 0.1000
Columns 11 through 16
0.1100 0.1200 0.1300 0.1400 0.1500 0.1600

카테고리

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