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

1 view (last 30 days)
fooozie mtlb
fooozie mtlb on 19 Oct 2015
Answered: Guillaume on 19 Oct 2015
fs=input('Enter the sampling rate value = ');
ind = (fix(linspace(1,length(he),fs)));
for y=ind(1,2)-1;
  1 Comment
fooozie mtlb
fooozie mtlb on 19 Oct 2015
This is what suppose i get.. but i still get error in dimension..

Sign in to comment.

Accepted Answer

Martin Schätz
Martin Schätz on 19 Oct 2015
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.

More Answers (1)

Guillaume on 19 Oct 2015
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
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.

Community Treasure Hunt

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

Start Hunting!