0

I have a cell array:

X =

{1x2} {1x2}


X{1} = '' A

X{1 2} = 10 113

I wish to concatenate the sub cells in such a way that

 Y = 10 113A

Thanks, S :-)

4 Answers 4

1
y = cellfun(@(a, b) sprintf('%d%s', b, a), x{1}, x{2}, 'UniformOutput', false);
Sign up to request clarification or add additional context in comments.

Comments

1

Assuming you have this cell array for X:

X = {{'' 'A'} {10 113}};

You can create your array Y using INT2STR and STRCAT:

Y = strcat(int2str([X{2}{:}].'),X{1}.').';

Comments

0

The Matlab File Exchange has a function written to do precisely this. uniqueRowsCA

2 Comments

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.
I added some info to help find the link should it change (unlikely with the MFE). Not sure what the essential parts of this would be.
-1

For those interested, I think I found a solution.

I redefined my cell array as:

X1 =

{1x2}

X1 = '' 'A'

X2 = 

[1x2 double]

X2 = 10 113

I then applied this for loop:

NUM = [];

for i = 1:size(X2')              #take the transpose of X2
    p = num2str(X2(i));          #convert doubles to strings
    str = STRCAT(p, X1(i));      #concatenate
    NUM = [NUM str];             #add to another array
end


NUM = '10' '113A'

I am sure there is a more efficient way but MATLAB and I will probably never be on good terms. Sometimes quick and dirty is sufficient!

Cheers, S :-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.