Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
getting error Subscript indices must either be real positive integers or logicals in finding distance?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello everyone, let say, i have cell matrix {[100*2],[450*2],[300*2],[999*2]....[898*2]}. Now i want to find a distance/derviative of each cell i.e, [100*2] and others cells. from below code i got the distance values by considering one point distance. but i want to get for each distance points are '3' similarly '5','13'. i am getting an error as Subscript indices must either be real positive integers or logicals.
load('myfile.mat');
for j = 1:length(Profile_number)
xy1 = Profile_number{j,1};
%calculate derivate of 1st element in xy1
d_begin = (xy1(2,2)-xy1(1,2))/(xy1(2,1)-xy1(1,1));
%calculate derivate of last element in xy1
d_end = (xy1(end,2)-xy1(end-1,2))/(xy1(end,1)-xy1(end-1,1));
d_main = [];
for k = 2:length(xy1(1:end,1))-1
d_1 = ((xy1(k+13,2)-xy1(k,2))/(xy1(k+13,1)-xy1(k,1)));
d_2 = ((xy1(k,2)-xy1(k-13,2))/(xy1(k,1)-xy1(k-13,1))); ***** getting error here as highlighted
d_k = 0.5*(d_1 + d_2);
d_main = [d_main;d_k];
end
d_main = [d_begin;d_main;d_end];
profilenumber{j,2} = d_main;
end
Thanks for your help inadvance
3 Commenti
Adam
il 26 Set 2018
I'm afraid I don't have the time to try to work out what your algorithm is attempting to do, I was just answering the question at hand which was why you get that error.
I also don't know what you mean by 'doesn't work out'. If you have the option selected then 'Pause on errors' will stop you at the right part of the code to investigate further.
Risposte (1)
Walter Roberson
il 26 Set 2018
Same issue as we told you before in https://www.mathworks.com/matlabcentral/answers/102145-why-do-i-get-the-error-subscript-indices-must-either-be-real-positive-integers-or-logicals#comment_614366
Your k needs to start at least 1 higher than the greatest magnitude that you subtract from your subscript. With you subtracting 13, your k needs to start at least at 14.
Your k needs to end at most at the length of the array minus the greatest magnitude that you add to your subscript. With you adding 13, your k needs to end at length(xy1(1:end,1))-13 or before.
Note: length(xy1(1:end,1)) can be better written as size(xy1, 1)
2 Commenti
Walter Roberson
il 19 Nov 2018
I notice that you marked that "Another Answer is better", but that there is no other answer. Are you continuing to have difficulty with the Question you had posted?
Questa domanda è chiusa.
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!