How would i use for loop to display the whole row of information based on userinput of the first collum. The data comes from an excel sheet.
1 view (last 30 days)
Find a recipe user input + Error Check
F = input(['Great! You chose to (Find A Recipe) now, please enter a material ', ...
'or item that you would like to see the recipe off! '], 's');
F = input('Sorry invalid choice, please try again! ','s');
for k = 1:1:length(F)
if F == All_data(k,1)
final_recipe = All_data(k,:);
fprintf('this is %f\n ',final_recipe)
Is just not working.
Ishan on 30 Nov 2022
If you want to loop over the entire row, it would be better to use indexing to extract the row number and display all elements of that particular row using All_data(idx,:)
You can search for the index (idx) using the find function along with strcmp to get that row number.
Here are links to a few concepts that would be useful for performing such operations:
1. Matrix Indexing: Using Logical in Array Indexing
2. Find array elements based on a specified condition
Alternatively, if you want to get the row with the DisplayName ‘XYZ’ based on the name in a given table (where DisplayName is the heading of that table column and XYZ is 1st element of the row to be extracted, you can use
>> data(data.DisplayName == 'XYZ', :)