Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to update a value in different raw after performing validity check at one raw?

조회 수: 1 (최근 30일)
KenL
KenL 2016년 10월 3일
마감: MATLAB Answer Bot 2021년 8월 20일
I have a file containing 5 raws including the titles and 3 columns. After performing a validity check for value at raw(2,2), I will need to update the raw(2,3) with another value. However, I failed to do so. Please advise.
  댓글 수: 4
KenL
KenL 2016년 10월 3일
file={'No','Question','Length';'1','how are you?','';'2','What is your name?','';'3','Where do you stay?','';'4','How old are you?',''}
I want to figure out the length for all the text columns.

답변 (2개)

Guillaume
Guillaume 2016년 10월 4일
If I understood correctly
file = {'No','Question','Length';'1','how are you?','';'2','What is your name?','';'3','Where do you stay?','';'4','How old are you?',''};
file(2:end, 3) = cellstr(num2str(cellfun(@numel, file(2:end, 2)))
will work. Or if you have R2016b:
file = {'No','Question','Length';'1','how are you?','';'2','What is your name?','';'3','Where do you stay?','';'4','How old are you?',''};
file = string(file);
file(2:end, 3) = file(2:end, 2).strlength;

Andrei Bobrov
Andrei Bobrov 2016년 10월 4일
편집: Andrei Bobrov 2016년 10월 4일
file(2:end,3) = cellfun(@(x)sprintf('%d',numel(x)),file(2:end,2),'un',0)

이 질문은 마감되었습니다.

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by