how could I loop value of n because dimension is mismatch?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
fooozie mtlb
il 19 Ott 2015
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
Risposta accettata
Martin Schätz
il 19 Ott 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.
0 Commenti
Più risposte (1)
Guillaume
il 19 Ott 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
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 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!