How to continue a count from the previous when calling each function? Attached photo explains further.

2 visualizzazioni (ultimi 30 giorni)
Refer to photo for further explanation.
All other data are correct expect the first column (Time).
Lines of code where I increment the time.:
From Function 1:
%% Looping the angles for each step
tic;
P2PAng = zeros(6); %preallocating memory
for j = 1:condiPTP
steploop = AngleA + j * step;
P2PAng(j,:) = steploop;
end
%% Increments of Time
TimeP2P = zeros(1); %preallocating memory
for clockPTP = 1:condiPTP
TickTockPTP = clockPTP * 0.1;
TimeP2P(clockPTP,:) = TickTockPTP;
end
toc
%% Concatenating Time & Point to Point Angles. Time will be the first column
ConcPTP = [TimeP2P,P2PAng];
From Function 2:
%% Looping through each point of the line
tic;
AnglesLin = zeros(6); %preallocating memory
for f = 1:ResLin
%% calculating actual point
A(1,1) = A(1,1) + DeltaX ;
A(1,2) = A(1,2) + DeltaY ;
A(1,3) = A(1,3) + DeltaZ ;
% Calling Inverse Kinematics
AnglesLin(f,:) = IKine(A);
end
%% Increments of Time
TimeLin = zeros(1); %preallocating memory
for clockLin = 1:ResLin
TickTockLin = clockLin * 0.1 + 10;
TimeLin(clockLin,:) = TickTockLin;
end
toc
%% Concatenating Time & Angles. Time will be the first column
ConcLin = [TimeLin,AnglesLin];
  3 Commenti
Konard Adams
Konard Adams il 30 Gen 2022
The idea is not asking anyone to do it for me. Just seeking advice from people with experience and knowledge with MATLAB.
What am I doing wrong here?
%% Increments of Time
TimeLin = zeros(1); %preallocating memory
for clockLin = 1:ResLin
TickTockLin = clockLin * 0.1 + 10;
TimeLin(clockLin,:) = TickTockLin;
end
It works for the first two calls. Is there a way that when the functions are called, they continue incrementing from the previous rather than starting over.

Accedi per commentare.

Risposta accettata

Voss
Voss il 30 Gen 2022
There are a few ways you could do this. Probably the easiest would be to remove the time calculation from Line.m and Point.m and instead prepend the time column to the results from Line() and Point() in the main function. Updated files are attached (IKine.m remains the same).
This way is probably better than hard-coding a time offset of 10 in Line.m. What would happen if you used a different size data set or a different time-step? What if you called the functions in a different order? Specifying the time column in the main function avoids those considerations entirely because you just make time be what it needs to be in that particular context.

Più risposte (0)

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by