- https://www.mathworks.com/help/matlab/ref/cell2mat.html
- https://www.mathworks.com/help/matlab/ref/double.unique.html
Ordering the elements of cells uniquely
2 ビュー (過去 30 日間)
古いコメントを表示
I have n cells. Each cell contains a couple of numbers. I need to uniquely order the (whole) numbers and save it in a matrix. How is that possible?
0 件のコメント
回答 (1 件)
Vandit
2024 年 9 月 29 日
Hello Amir,
You can use the "cell2mat" function in MATLAB to convert a cell array into a matrix, followed by the "unique" function to get the unique values.
Below is the code snippet for reference:
n = 3; % Number of cells
cellArray = {1, [2, 3], [3, 4, 5]};
% Convert cell array to matrix
matrix = cell2mat(cellArray);
% Get unique values and sort them
uniqueValues = unique(matrix);
disp(uniqueValues);
The above code will give you a sorted array of unique numbers from the cells. To know more about "cell2mat" and "unique" functions, please refer to the following documentations:
Hope this helps.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!