Call the data in string

3 visualizaciones (últimos 30 días)
fyza affandi
fyza affandi el 10 de Mzo. de 2019
Respondida: madhan ravi el 10 de Mzo. de 2019
Let say I have a set of matrices
apple=[1 0 0
1 0 1];
orange=[1 0 0 1
1 1 1 0];
guava=[1 1 0 1
1 0 1 0];
Then I save it in a vector name fruit
fruit={'apple','orange','guava'}
Let say I want the matrix for orange, how can I do it?

Respuestas (2)

Walter Roberson
Walter Roberson el 10 de Mzo. de 2019
fruit_vals = {apple, orange, guava};
to_find = 'orange';
[tf, idx] = ismember(tolower(to_find), tolower(fruit));
if ~tf
fprintf('"%s" is not a known fruit\n', to_find);
associated_val = [];
else
associated_val = fruit_vals{idx};
end

madhan ravi
madhan ravi el 10 de Mzo. de 2019
fruit.apple=[1 0 0
1 0 1];
fruit.orange=[1 0 0 1
1 1 1 0];
fruit.guava=[1 1 0 1
1 0 1 0];
fruit.('orange')

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by