Hello,
I have been trying to look if someone else had a similar question. But not sucess so I want to ask. How would you approach merging two columns with strings as the picture below? Thanks in advance

1 Comment

How is your data imported in MATLAB? This looks like Excel.

Sign in to comment.

 Accepted Answer

Carson Purnell
Carson Purnell on 16 Jun 2022
Edited: Carson Purnell on 16 Jun 2022
given column 1==A and column 2==B, this stacks those columns without sorting.
%example arrays
A = {'a',1;'b',2}; B = {'c',11;'n',12};
vertcat(A,B)
Pretty simple. But it is unclear what your data is, how it is organized, or what your specific intent is. Please provide more details.

6 Comments

It was only an example to illustrate how I wanted to organize these points - I thought it was more neat. Similar to, for example, if I were to write
Column 1
A = 1
B = 2
C = 3
Column 2
A1 =4
B1 = 5
C1 = 6
It is not illustrative, because the question is about matlab and these examples do not conform to any sort of data type or structure standard. If my answer works, neat. If it doesn't, just explain how the data actually is organized on input and how you want it reformulated.
Sorry, this is a screeshot of my data in matlab. These are coordinates that will help develop a CAD model more efficiently. So this is how I organize my data in matlab so I avoid making mistakes when I convert it into a text file to be used in Solidworks. But I found out that in SOLIDworks, it would work faster if I can make these coordinates in the following way, for example:
FP1 (first column) = 0.0932
FP1 (second column) = 0.2245
FP1 (third column) = 0.1855
So I thought to ask if maybe I can get these coordinates organize as I illustrated above.
Carson Purnell
Carson Purnell on 16 Jun 2022
Edited: Carson Purnell on 16 Jun 2022
in that case you only have matrix A so cat across those pairs of columns:
b = vertcat(A(:,1:2),A(:,3:4), etc for the number of columns, minus whatever your headings are.
Ideally, you just don't generate across multiple columns like that. Might be some trick with reshape() to make it 2xN without scrambling, but I don't know it.
I have seen like two other people ask this question, and they dont get any answer. I will keep trying - it is nothing crucial- it is just to save me time.
Carson Purnell
Carson Purnell on 16 Jun 2022
Edited: Carson Purnell on 16 Jun 2022
You don't need to keep trying, if you read my comment I have provided the code to do it. Just inches upward on the screen. Make sure to read the documentation on vertcat.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!