how could I loop value of n because dimension is mismatch?
1 回表示 (過去 30 日間)
古いコメントを表示
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
採用された回答
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.
0 件のコメント
その他の回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!