How to concatenate data from two different functions in MATLAB?

Part of one function has this:
%% Concatenating Time & Point to Point Angles. Time will be the first column
ConcPTP1 = [TimeP2P1,P2PAng1]; %% getting the datat from here works
Part of the other function has this:
%% Concatenating Time & Angles. Time will be the first column
ConcLin1 = [TimeLin1,AnglesLin1]; %% getting the datat from here works too
Part of the main program has this
%% Collecting all Data
Concat = [ConcPTP1',ConcLin1']'; %%% ***my problem is here*** works only if everything is in one script
This works when everything is a single script but gives errors when I seperate the files as functions then call them from a main program. (The function method is needed). Everything else works fine, I only need to combine all the data from both functions as one ouput file.
Thank you in advance.

5 commentaires

You need to return the ConcPTP1 and ConcLin1 variables as outputs from your functions. Can you show us the code for these function signatures and how you are currently calling them?
As James suggests, add ConcLin1 as an output from Line(), and add ConcPTP1 as an output from Point()
@Walter Roberson @James Tursa thank you. Your suggestion helped a great deal.
As you correctly mentioned for Line:
% Before:
% function AnglesLin1 = Line(nx, ny, nz, sx, sy, sz, ax, ay, az,ResLin1,Xstart,Ystart,Zstart,Xend,Yend,Zend)
% correction:
function [AnglesLin1,ConcLin1] = Line(nx, ny, nz, sx, sy, sz, ax, ay, az,ResLin1,Xstart,Ystart,Zstart,Xend,Yend,Zend)
As you correctly mentioned for Point:
% Before:
% function AnglesPTP1 = Point(X, Y, Z, nx, ny, nz, sx, sy, sz, ax, ay, az,iniPTP1,condiPTP1)
% correction:
function [AnglesPTP1,ConcPTP1] = Point(X, Y, Z, nx, ny, nz, sx, sy, sz, ax, ay, az,iniPTP1,condiPTP1)
Also the script for calling Point must be corrected as well :
%% Calling PTP Motion
% Before:
% PTPIKine = Point(X, Y, Z, nx, ny, nz, sx, sy, sz, ax, ay, az,iniPTP1,condiPTP1);
% correction:
[AnglesPTP1,ConcPTP1] = Point(X, Y, Z, nx, ny, nz, sx, sy, sz, ax, ay, az,iniPTP1,condiPTP1);
Script for calling Line:
%% Calling Linear Motion
% Before:
% LineIKine = Line(nx, ny, nz, sx, sy, sz, ax, ay, az, ResLin1,Xstart,Ystart,Zstart,Xend,Yend,Zend);
% correction:
[AnglesLin1,ConcLin1] = Line(nx, ny, nz, sx, sy, sz, ax, ay, az, ResLin1,Xstart,Ystart,Zstart,Xend,Yend,Zend);
[ConcPTP1',ConcLin1']'
Three ctranpose operations seems a bit inefficient: why not just concatenate with the correct orientation in the first place?
I am guessing something like this might wrk:
[ConcPTP1;ConcLin1]
If that is not possible, replace the complex conjugate transpose with transpose.
Thank you @Stephen. Fantastic idea. I tried it and it gives the same output. Much simpler way, indeed.
Hence MATLAB community is important. Cheers!

Connectez-vous pour commenter.

 Réponse acceptée

Konard Adams
Konard Adams le 20 Jan 2022
Modifié(e) : Konard Adams le 20 Jan 2022
How to concatenate data from two different functions in MATLAB?
Functions:
1)
% Before:
% function AnglesLin1 = Line(nx, ny, nz, sx, sy, sz, ax, ay, az,ResLin1,Xstart,Ystart,Zstart,Xend,Yend,Zend)
% correction:
function [AnglesLin1,ConcLin1] = Line(nx, ny, nz, sx, sy, sz, ax, ay, az,ResLin1,Xstart,Ystart,Zstart,Xend,Yend,Zend)
2)
% Before:
% function AnglesPTP1 = Point(X, Y, Z, nx, ny, nz, sx, sy, sz, ax, ay, az,iniPTP1,condiPTP1)
% correction:
function [AnglesPTP1,ConcPTP1] = Point(X, Y, Z, nx, ny, nz, sx, sy, sz, ax, ay, az,iniPTP1,condiPTP1)
Script:
%% Calling PTP Motion
% Before:
% PTPIKine = Point(X, Y, Z, nx, ny, nz, sx, sy, sz, ax, ay, az,iniPTP1,condiPTP1);
% correction:
[AnglesPTP1,ConcPTP1] = Point(X, Y, Z, nx, ny, nz, sx, sy, sz, ax, ay, az,iniPTP1,condiPTP1);
%% Calling Linear Motion
% Before:
% LineIKine = Line(nx, ny, nz, sx, sy, sz, ax, ay, az, ResLin1,Xstart,Ystart,Zstart,Xend,Yend,Zend);
% correction:
[AnglesLin1,ConcLin1] = Line(nx, ny, nz, sx, sy, sz, ax, ay, az, ResLin1,Xstart,Ystart,Zstart,Xend,Yend,Zend);
Now, using the line of code below works to concatenate the needed values:
%% Collecting all Data
% Before:
Concat = [ConcPTP1',ConcLin1']';
% A Simpler way is:
Concat = [ConcPTP1;ConcLin1];

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Identification dans Centre d'aide et File Exchange

Produits

Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by