how to concatenate in matlab?

A=power; load ;density;
b=_mean;_std;_max;_min;
A is a set of string in .txt file 1 and B is a set of string in .txt file 2. I need to concatenate the corresponding strings in both text files and put it in the excel sheet, such that ,i need output as,
power_mean power_std power_max power_min load_mean and so on.
It should be stored in excel in a row(1*12). its nothing like creating header or label to my values. im stuck here... help me

3 commentaires

Walter Roberson
Walter Roberson le 12 Août 2013
How do strings "correspond" ? The 5th A corresponds to the 5th B? Or the content of one needs to be searched in the content of the other?
How are you representing the strings? As cell arrays or as arrays of characters?
Please give an example of a line from each of the files.
sandy
sandy le 12 Août 2013
strings in A is present in file header_01.txt in (3*1),also strings in b in header_02.txt in(4*1).i am loading both files to A and b in cell arrays only.
Inside A, power load density ; Inside b, mean std max min
my output should be in excel file and output come like, power_mean in 1*1,power_std in 1*2 and so on.below in each cells(1*12) in excel file
power_mean power_std power_max power_min load_mean and so on.
Andrei Bobrov
Andrei Bobrov le 12 Août 2013
see my answer

Connectez-vous pour commenter.

Réponses (1)

Andrei Bobrov
Andrei Bobrov le 12 Août 2013
Modifié(e) : Andrei Bobrov le 12 Août 2013

0 votes

A={'power'; 'load' ;'density'};
b={'mean';'std';'max';'min'};
[ii,jj] = ndgrid(1:numel(b),1:numel(A));
out = reshape(strcat(A(jj),{'_'},b(ii)),1,[]);
ADD
nm = {'E:\header_01.txt','E:\header_02.txt'};
c1 = cell(1,2);
for jj = 1:2
f = fopen(nm{jj});
c = textscan(f,'%s');
fclose(f);
a1 = regexp(c{:},'\w*','match');
c1{jj} = cat(1,a1{:});
end
n = cellfun('length',c1);
[ii,jj] = ndgrid(1:n(2),1:n(1));
out = reshape(strcat(c1{1}(jj),{'_'},c1{2}(ii)),1,[]);

4 commentaires

Walter Roberson
Walter Roberson le 12 Août 2013
You can ndgrid cell arrays of strings? I never knew that!
Andrei Bobrov
Andrei Bobrov le 12 Août 2013
Oh! I used Octave! Corrected. Thank you Walter!
sandy
sandy le 12 Août 2013
hi Andrei,...thanks for ur reply... but it showing error if i run this code as, ??? Undefined function or method 'full' for input arguments of type 'cell'.
Error in ==> ndgrid at 38 varargin{i} = full(varargin{i}); % Make sure everything is full
Error in ==> append at 3 [ii,jj] = ndgrid(b,A);
Andrei Bobrov
Andrei Bobrov le 12 Août 2013
I did all the corrections.

Connectez-vous pour commenter.

Question posée :

le 12 Août 2013

Community Treasure Hunt

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

Start Hunting!

Translated by