I want to Access value by using its key , the login should to be like if user enter key1 it should match with key1 keyword from excel sheet and give value_1 as output.

1 visualizzazione (ultimi 30 giorni)
I want to Access value by using its key , the login should to be like if user enter key1 it should match with key1 keyword from excel sheet and give value_1 as output.

Risposte (2)

Karim
Karim il 6 Lug 2022
Hi, you can compare the strings of the key with the user input, and then use that index to retrieve the value:
UserInput = "key1";
MyData = ["key1" "value_1";
"key2" "value_2";
"key3" "value_3"];
% look for the index of the "key"
Idx = contains(MyData(:,1),UserInput);
if any(Idx)
% extract the coressponding "value"
MyOutput = MyData(Idx,2);
else
disp('no matching key found')
end
MyOutput
MyOutput = "value_1"

Steven Lord
Steven Lord il 6 Lug 2022
Take a look at the containers.Map function.

Categorie

Scopri di più su Tables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by