Best way to retrieve items from a cell array using a cell array of indices?
Hi I am porting a script I had in Python to Matlab. Also returning to MATLAB after a decade, so pardon me if it’s too basic.
The key issue I am having is, retrieving premapped items from a cell array. Example, I have:
label_names={"assds", "Sasas", "Asasa", "assds"}
indices={[1 3 2]} %note that this can have varying lengths from 1 to full length of the label array.
label_names(indices) %of course returns an error
Error is "Unable to use a value of type cell as an index."
What is the best way to achieve this – retreive items based on a cell array of indices – as cleanly as possible?
PS: The reason they are cell arrays has to do with varying lengths. To avoid X-Y problem, lets assume rest of the code is done optimally.
Thanks!Hi I am porting a script I had in Python to Matlab. Also returning to MATLAB after a decade, so pardon me if it’s too basic.
The key issue I am having is, retrieving premapped items from a cell array. Example, I have:
label_names={"assds", "Sasas", "Asasa", "assds"}
indices={[1 3 2]} %note that this can have varying lengths from 1 to full length of the label array.
label_names(indices) %of course returns an error
Error is "Unable to use a value of type cell as an index."
What is the best way to achieve this – retreive items based on a cell array of indices – as cleanly as possible?
PS: The reason they are cell arrays has to do with varying lengths. To avoid X-Y problem, lets assume rest of the code is done optimally.
Thanks! Hi I am porting a script I had in Python to Matlab. Also returning to MATLAB after a decade, so pardon me if it’s too basic.
The key issue I am having is, retrieving premapped items from a cell array. Example, I have:
label_names={"assds", "Sasas", "Asasa", "assds"}
indices={[1 3 2]} %note that this can have varying lengths from 1 to full length of the label array.
label_names(indices) %of course returns an error
Error is "Unable to use a value of type cell as an index."
What is the best way to achieve this – retreive items based on a cell array of indices – as cleanly as possible?
PS: The reason they are cell arrays has to do with varying lengths. To avoid X-Y problem, lets assume rest of the code is done optimally.
Thanks! cell array, indexing MATLAB Answers — New Questions