cell, find cell, matlab
3 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Prateekshya
on 25 Jul 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.
0 Comments
See Also
Categories
Find more on Java Package Integration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!