cell, find cell, matlab

2 visualizaciones (últimos 30 días)
Tomas
Tomas el 20 de Nov. de 2013
Respondida: Prateekshya el 25 de Jul. de 2024
i have cell Z=(1x7) Z{1}=[1x3 double] [1x3 double] [1x3 double] [1x3 double] [1x3 double] [1x3 double]
Column 7
1x3 double]
How do I find and index the value of the position Z{1}{1}(1) ? for example i find value 2.5, she is of the position Z{1}{7}(1)
Thank you for your answers

Respuestas (1)

Prateekshya
Prateekshya el 25 de Jul. de 2024
Hi Tomas,
From the example I figured out that you want to determine the index of a given value in a matrix. To solve this problem, you can use the concept of hashing. That means you can store the value and the index in a map. For example, if there is a 2D matrix:
1 9 7
11 4 2
Then the map will look like:
1 -> "1,1"
9 -> "1,2"
7 -> "1,3"
11 -> "2,1"
4 -> "2,2"
2 -> "2,3"
You can store the above data and extract the information as per the requirement. MATLAB does not provide any data structure for this purpose. You can use Java collections in MATLAB by importing them. Please refer to the below example for the same.
import java.util.HashMap
% Step 1: Create a Java HashMap
hashMap = java.util.HashMap();
% Step 2: Populate the HashMap with key-value pairs
hashMap.put(1,'1,1');
hashMap.put(11,'2,1');
% Step 3: Retrieve values from the HashMap
index = hashMap.get(11);
% Display the retrieved values
disp(['Index for 11: ', index]);
You can change the format of the data being stored in the map as per the requirement. I hope this helps!
Thank you.

Categorías

Más información sobre Java Package Integration en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by