フィルターのクリア

How to count the length of a raw?

3 ビュー (過去 30 日間)
KenL
KenL 2016 年 10 月 4 日
コメント済み: KenL 2016 年 10 月 5 日
I have a matrix as follow and would like to read a value from raw(x,2) and perform a length count follow by updating such length count value to (x,3) respectively. x refers to the row.
file={'No','Question','Length';'1','how are you?','';'2','What is your name?','';'3','Where do you stay?','';'4','How old are you?',''}. I tried many ways but the returned length count for all texts is always 1. Won't the length should be based on the actual length of the text e.g. Text='how are you?'; The returned length count should be 12 rather than 1..right?
  1 件のコメント
Andrei Bobrov
Andrei Bobrov 2016 年 10 月 4 日
repeat the question

サインインしてコメントする。

採用された回答

KSSV
KSSV 2016 年 10 月 4 日
Yes length of the text shall change. But you have named the strings in file in the form of cell. You can access the text using f{i,j}.
file={'No','Question','Length';'1','how are you?','';'2','What is your name?','';'3','Where do you stay?','';'4','How old are you?',''} ;
[m,n] = size(file) ;
L = zeros(m,n) ;
for i = 1:m
for j = 1:n
L(i,j) = length(file{i,j})
end
end
  4 件のコメント
KSSV
KSSV 2016 年 10 月 4 日
[num,txt,raw]=xlsread(file);
num - gives only numbers txt - gives headers if any raw - gives data in the form of cells.
To waht you have applied the above code? You shall apply to raw.
KenL
KenL 2016 年 10 月 5 日
I managed to solve the problem. Thanks Dr.

サインインしてコメントする。

その他の回答 (1 件)

michio
michio 2016 年 10 月 4 日
編集済み: michio 2016 年 10 月 4 日
Not sure if I understand your issues correctly, but do you happen to use ()? To see the length of the text inside of the cell, you need to use a curly bracket instead {}.
file={'No','Question','Length';'1','how are you?','';'2','What is your name?','';'3','Where do you stay?','';'4','How old are you?',''};
size(file{1,2})
  1 件のコメント
Guillaume
Guillaume 2016 年 10 月 4 日
numel would be better than size for a vector. size always return a vector of at least 2 elements.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by