How to update a value in different raw after performing validity check at one raw?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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 Comments
Massimo Zanetti
on 3 Oct 2016
Please, upload an example of you matrix
Guillaume
on 3 Oct 2016
I assume by raw you mean row? Otherwise, I have no idea what you're talking about.
We have no idea how you're reading the file nor what is in it. Files don't have titles or columns as such, so please show us the code that is not working, or an example file.
KenL
on 3 Oct 2016
KenL
on 4 Oct 2016
Answers (2)
Guillaume
on 4 Oct 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
on 4 Oct 2016
Edited: Andrei Bobrov
on 4 Oct 2016
file(2:end,3) = cellfun(@(x)sprintf('%d',numel(x)),file(2:end,2),'un',0)
This question is closed.
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!