strcat(strings) to call a variable or matrix

4 vues (au cours des 30 derniers jours)
David
David le 30 Avr 2014
Commenté : Cedric le 30 Avr 2014
I have a While loop that looks like this:
Zone1 = ...;
Zone2 = ...;
Zone3 = ...;
...
Zone9 = ...;
a = 1;
while a <= 9
TrueOrFalse = Subfunction(strcat('Zone',num2str(a)));
%Subfunction outputs 0 or 1
if TrueOrFalse == 0
break % end while loop
end % end if statement
a = a+1;
end % end while loop
Now, the problem I'm running into in Debug mode is that the strcat(strings) function is outputting a string that is correct, but it's not calling on the previously established variable or matrix.
What can I do to make that work?

Réponse acceptée

Cedric
Cedric le 30 Avr 2014
Modifié(e) : Cedric le 30 Avr 2014
You want to store your zone data in a numeric array or a cell array, and then index it for passing the relevant data item to the sub function.
For numeric data:
zonesData = [100, 800, 1750] ;
for k = 1 : length( zonesData )
isOk = SubFunction( zonesData(k) ) ;
if ~isOk
break ;
end
end
For other types of data, e.g. strings:
zonesData = {'USA', 'CH', 'FR'} ;
for k = 1 : length( zonesData )
isOk = SubFunction( zonesData{k} ) ;
if ~isOk
break ;
end
end
  4 commentaires
David
David le 30 Avr 2014
This! This made everything possible. Thank you!
Cedric
Cedric le 30 Avr 2014
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Language Fundamentals dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by