how to find the location of a specific element in a matrix or in a excel file

8 vues (au cours des 30 derniers jours)
Aiman Zara
Aiman Zara le 9 Avr 2023
Commenté : dpb le 10 Avr 2023
i need to find the location of each element from the matrix/excel, how can i do it through matlab functions? if not possible with functions than how ca I do this with loop? please provide me a sample code to do so. Actually I think functions would work great for large data processing, loops will take more time. Attaching a sample file

Réponse acceptée

dpb
dpb le 9 Avr 2023
What do you mean "to find the location of each element"? You mean just read the file, don't you; the location is really of very little significance for a regular file structure such as that file contains. I'd do something like
fn='https://www.mathworks.com/matlabcentral/answers/uploaded_files/1350129/example.xlsx';
tData=readtable(fn);
tData=convertvars(tData,@iscellstr,'categorical')
tData = 5×3 table
Stage health Object _____ _______ ______ 1 good chair 2 good table 3 bad fan 4 average bag 5 average laptop
  4 commentaires
Aiman Zara
Aiman Zara le 10 Avr 2023
Thankyou, it worked
however at first, This error showed up:
Undefined function 'matches' for input arguments of type 'string'.
Error in CSV (line 20)
[r,c]=find(matches(data,lookupValue)) % return locations
I then placed "strcmp" instead of matches,
[r,c]=find(strcmp(data,lookupValue)) % return locations
and then output dispalyed the rows and coloumn of the given name
dpb
dpb le 10 Avr 2023
matches didn't show up until R2019b party....

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by