whats wrong with this code?
1 次查看(过去 30 天)
显示 更早的评论
Hi I am getting the disp output four times instead of three which is correct and should be displayed after executing this code:
function where_is_solution_required(lit_kolonne)
form_uten_tiltak='SANDSTEIN';
for k=1:size(lit_kolonne,1)
my_lit=lit_kolonne(k);
if (strcmpi(my_lit,form_uten_tiltak))
continue
end
disp('Tiltaket for sonen settes i gang')
end
end
3 个评论
Guillaume
2019-1-11
Your reasoning is correct. Therefore we can surmise that your input does not contain 4 cells, or that it contains 4 cells and that none of them contains sandstein. The only way to know for sure is if you share that input (as a mat file).
By the way, why write:
if (strcmpi(my_lit,form_uten_tiltak))
continue
end
disp('Tiltaket for sonen settes i gang')
when
if ~strcmp(my_lit, uten_tiltak)
disp('Tiltaket for sonen settes i gang');
end
is simpler and clearer.
回答(3 个)
Luna
2019-1-11
Try this below:
function where_is_solution_required(lit_kolonne)
form_uten_tiltak = 'SANDSTEIN';
for k=1:numel(lit_kolonne)
my_lit=lit_kolonne{k};
if ~(strcmpi(my_lit,form_uten_tiltak))
disp('Tiltaket for sonen settes i gang')
end
end
end
4 个评论
Luna
2019-1-11
编辑:Luna
2019-1-11
char array, cell array, double array are different things.
Continue is working in my machine with that code. Are you sure that SANDSTEIN is all upper case? Maybe yours is not working because of case sensitivity. Which version of Matlab you are using?
Read about strcmpi and strcmp.
Muazma Ali
2019-1-11
5 个评论
Image Analyst
2019-1-11
Muazma, why are you refusing to attach your data in a .mat file with the paper clip icon like Guillaume requested?
I sense he's about to give up trying to help you and move on to easier questions.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Database Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!