how could I loop value of n because dimension is mismatch?

1 回表示 (過去 30 日間)
fooozie mtlb
fooozie mtlb 2015 年 10 月 19 日
回答済み: Guillaume 2015 年 10 月 19 日
fs=input('Enter the sampling rate value = ');
ind = (fix(linspace(1,length(he),fs)));
for y=ind(1,2)-1;
z=1:fs;
n(z)=((y*(z))-y)+1:y*(z);
end
  1 件のコメント
fooozie mtlb
fooozie mtlb 2015 年 10 月 19 日
n1=1-24
n2=25-48
n3=49-72
ect...
This is what suppose i get.. but i still get error in dimension..

サインインしてコメントする。

採用された回答

Martin Schätz
Martin Schätz 2015 年 10 月 19 日
Hi, I dont understand what you are doing... why to load fs when your ind is then fixed that ind=[1:length(he)], and why do you use for, when its done only once?
Then your n(z)= is expecting fs values but you put there only 2, that is the dimension mismatch. The ((y*(z))-y)+1:y*(z) should be 1 value (and then you have go through z) or fs values.

その他の回答 (1 件)

Guillaume
Guillaume 2015 年 10 月 19 日
There's something that does not make sense on nearly every line you've written:
ind = (fix(linspace(1,length(he),fs)));
Why the () brackets around the fix? They don't do anything. Is something missing?
for y=ind(1,2)-1;
You don't usually have a semicolon at the end of a for line. Also, since ind is a vector, ind(1, 2) is the same as ind(2). But more importantly, since ind(2)-1 is just a single number, the for doesn't do anything and the line is the same as
y = ind(2);
I.E. there's no looping at all
n(z)=((y*(z))-y)+1:y*(z);
Again, why the bracket around the z in y*(z). Why not use the simpler y*z. Note that since y is scalar and z is a vector, y*z is also a vector. So we have a colon between two vectors. While colon between two vectors work in matlab, it is equivalent to colon between the first element of each vector. I strongly doubt that's what you meant. In the end this line is equivalent to
n(z) = y*z(1)-y+1 : y*z(1); %Most likely not what you wanted
The colon in the above line will produce a vector a vector of length y+2 which is equal to ind(2)+2. You're trying to assign that to n(z) a vector of the same length as z which is equal to floor(fs). In all likely ind(2)+2 is not equal to floor(fs) so the assignment will fail with dimension mismatch.
In summary, your code does not make sense. Please explain what you're trying to do.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by