フィルターのクリア

I have a cell (NewCell {1,1}) with 1 column and many rows, each row has or '0' or []. If its '0', I want to make a comparison; if its the other thing, i want a 'V'.

1 回表示 (過去 30 日間)
Eduardo Rocha
Eduardo Rocha 2016 年 11 月 8 日
編集済み: Eduardo Rocha 2016 年 11 月 8 日
teste2 = cell(size(catconsumo));
for k=2:(length(Preos2013S1)-1)
if NewCell{1,1}{k} == '0'
mask = strcmp(catracio1, 'low') & strcmp(catpreco, 'high');
teste2(mask) = {'A'};
mask = strcmp(catracio1, 'medium low') & strcmp(catpreco, 'medium high');
teste2(mask) = {'B'};
mask = strcmp(catracio1, 'medium') & strcmp(catpreco, 'medium');
teste2(mask) = {'C'};
mask = strcmp(catracio1, 'medium high') & strcmp(catpreco, 'medium low');
teste2(mask) = {'D'};
mask = strcmp(catracio1, 'high') & strcmp(catpreco, 'low');
teste2(mask) = {'E'};
elseif NewCell{1,1}{k} ~= '0'
teste2{k}='V';
end
end
However, teste2 results with [] in every row, or one of those letters, but regardless of there is a [] or a '0' in NewCell{1,1}. Its not respecting the 'if' condition. Can somebody help me please?
  1 件のコメント
bemin
bemin 2016 年 11 月 8 日
You need to give little more details about your cell, However What I see from your code that you are trying to compare number with a string so you ether use strcmp () or write the if without quotations just like this:-
if NewCell{1,1}{k} == 0
...
...
..
etc.
I hope I can help

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

回答 (1 件)

James Tursa
James Tursa 2016 年 11 月 8 日
編集済み: James Tursa 2016 年 11 月 8 日
elseif isempty(NewCell{1,1}{k})
The problem you are having is that the result of NewCell{1,1}{k} ~= '0' is empty in that branch, not true, so you don't get into the elseif block.
Or, if you know for sure that there are only '0' and [] in NewCell{1,1}{k}, you could just turn that entire elseif statement into an else. E.g.,
else
teste2{k}='V';
  1 件のコメント
Eduardo Rocha
Eduardo Rocha 2016 年 11 月 8 日
編集済み: Eduardo Rocha 2016 年 11 月 8 日
Actually it seemed to work, but in fact it does not. I forgot to add some information:
When NewCell(1,1){k} is '0' and none of those conditions are satisfied, teste2(k) should be '0'. When NewCell(1,1){k} is [], teste2 should be 'V'.
However, teste2 is being [] for situations in which NewCell(1,1){k} is '0' and sometimes its making the comparison when NewCell(1,1){k} is [], which can't happen.
In teste2, there should only be '0', 'A', 'B', 'C', 'D', 'E' and 'V'

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

カテゴリ

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