combine two cell into one string
5 次查看(过去 30 天)
显示 更早的评论
Hello
I have attached SummaryResult.xlsx
eg.
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', .....]
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 个评论
采纳的回答
Chunru
2022-8-2
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)
更多回答(4 个)
dpb
2022-8-2
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
2022-8-2
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
2022-8-2
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
2022-8-2
1 个评论
Cris LaPierre
2022-8-2
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!