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!