Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

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

1 visualización (últimos 30 días)
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 comentarios
KenL
KenL el 3 de Oct. de 2016
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.

Respuestas (2)

Guillaume
Guillaume el 4 de Oct. de 2016
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 el 4 de Oct. de 2016
Editada: Andrei Bobrov el 4 de Oct. de 2016
file(2:end,3) = cellfun(@(x)sprintf('%d',numel(x)),file(2:end,2),'un',0)

La pregunta está cerrada.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by