cell, find cell, matlab

조회 수: 3 (최근 30일)
Tomas
Tomas 2013년 11월 20일
답변: Prateekshya 2024년 7월 25일
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

답변 (1개)

Prateekshya
Prateekshya 2024년 7월 25일
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.

카테고리

Help CenterFile Exchange에서 Java Package Integration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by