Get Index of Different Cell Value Between Multiple Cell Array

2 ビュー (過去 30 日間)
Angga Lisdiyanto
Angga Lisdiyanto 2016 年 7 月 1 日
コメント済み: Angga Lisdiyanto 2016 年 7 月 1 日

Hi, i want to get index of different cell value between multiple cell array using result of strcmp.

I know how to use strcmp.

In example :

cell_array_1 = {
                 'love', 'love', 'love';
                 'love', 'love', 'love';
                 'love', 'love', 'love';
                 'love', 'love', 'love';
               }
cell_array_2 = {
                 'love', 'love', 'love';
                 'love', 'peace', 'love';
                 'love', 'love', 'peace';
                 'love', 'love', 'love';
               }

Using strcmp :

strcmp(cell_array_1, cell_array_2)
>>
strcmp_result = 
'1' '1' '1'
'1' '0' '1'
'1' '1' '0'
'1' '1' '1'

The purpose is, i want to get '0' elemen's index. So i can change their font's color on UI table.

I just know how to change the font's color like this (for UI table) :

for i_row = 1:size(strcmp_result, 1)
   for i_column = 1:size(strcmp_result, 2)
      strcmp_result(i_row, i_column) = strcat('<html><body bgcolor="#ffe097" text="#794044">', strcmp_result(i_row, i_column));
   end
end

With above code, the whole font of table is colored.

How to give spesific index from strcmp?

Thanks in advance.

採用された回答

Walter Roberson
Walter Roberson 2016 年 7 月 1 日
Your strcmp_result is not a cell array of strings like you show: it will be an array of logical.
for i_row = 1:size(strcmp_result, 1)
for i_column = 1:size(strcmp_result, 2)
if strcmp_result(i_row, i_column)
strcmp_result_str{i_row, i_column} = '1';
else
strcmp_result_str{i_row, i_column} = '<html><body bgcolor="#ffe097" text="#794044">0';
end
end
end
Now set strcmp_result_str as the Data for the uitable

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by