combine two cell into one string
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Santosh Biradar
el 2 de Ag. de 2022
Comentada: Cris LaPierre
el 2 de Ag. de 2022
Hello
I have attached SummaryResult.xlsx
eg.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1085380/image.png)
here, I need data as
for A3 B3 it should be aaa_20220623
same for A4 B4, aaa_20220413
I want them to be collected in variable called eg, Newlyaddednames[] = ['aaa_20220623', 'aaa_20220413', .....]
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1085385/image.png)
for this
for A21 B21 it should be aaa_20220623
same for A22 B22, aaa_20220413
I want them to be collected in variable called eg, Missingdatanames[] = ['aaa_20220623', 'aaa_20220413', .....]
Thank you
Please let me know for more brief
0 comentarios
Respuesta aceptada
Chunru
el 2 de Ag. de 2022
t = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1085370/SummaryResult%20-%20Copy.xlsx');
t = t(1:6,1:4)
t.Missingdatanames = string(t.PLDStatus)+"_"+string(t.BLFFileName)
Más respuestas (4)
dpb
el 2 de Ag. de 2022
opt=detectImportOptions('SummaryResult - Copy.xlsx');
opt.VariableTypes(1:2)={'char'};
tG=readtable('SummaryResult - Copy.xlsx',opt);
tG.New=join(tG{:,1:2},'_');
yields
>> tG.New
tG.New =
23×1 cell array
{'aaa_20220623' }
{'aaa_20220413' }
{'aaa_20220903' }
{'aaa_20221322' }
{'aaa_20220123' }
{'aaa_20220620' }
{'_' }
{'_' }
{'_' }
{'_' }
{'_' }
{'_' }
{'_' }
{'_' }
{'_' }
{'_' }
{'_' }
{'MissingData_' }
{'PLD Status_BLF File Name'}
{'aaa_20220623' }
{'aaa_20220413' }
{'aaa_20220903' }
{'aaa_20221322' }
>>
Select as desire with logical addressing those rows of interest; not clear what the deal is about all the missing stuff and other data like headers in the column, you'll know what to do with that.
Default input scanning returned the second column as numeric, not text, hence the use of DetectImportOptions to set the data type.
Cris LaPierre
el 2 de Ag. de 2022
I would do this in 2 steps.
file = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1085370/SummaryResult%20-%20Copy.xlsx';
newlyAdded = readtable(file, 'Range','A2:P8','TextType','string')
Newlyaddednames = newlyAdded.PLDStatus + "_" + num2str(newlyAdded.BLFFileName)
missingData = readtable(file,'Range','A21:P25','TextType','string')
Missingdatanames = missingData.PLDStatus + "_" + num2str(missingData.BLFFileName)
David Hill
el 2 de Ag. de 2022
c=readtable('SummaryResult - Copy.xlsx');
m=[cell2mat(c.PLDStatus([1:6,20:23])),repmat('_',10,1),num2str(c.BLFFileName([1:6,20:23]))];
Santosh Biradar
el 2 de Ag. de 2022
1 comentario
Cris LaPierre
el 2 de Ag. de 2022
It all depends on how you read in the table. Preview your table, or at least the variable names, to see. By default, MATLAB will convert the column names to valid variable names unless you preserve variable names using the "VariableNamingRule","preserve" name-value pair.
file = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1085370/SummaryResult%20-%20Copy.xlsx';
dflt = readtable(file);
head(dflt)
dflt.BLFFileName(1)
% Now do the same but with the 'preserve' option
preserve = readtable(file,"VariableNamingRule","preserve")
head(preserve)
preserve.('BLF File Name')(1)
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!