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 Center および File ExchangeJava Package Integration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by