how to save different size of user groups in a cell array.

4 ビュー (過去 30 日間)
SHAIFALI
SHAIFALI 2024 年 6 月 9 日
回答済み: Arun 2024 年 6 月 20 日
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in DNUA (line 73)
feasibleGroups = [feasibleGroups; groups_k];
>>
  1 件のコメント
Manikanta Aditya
Manikanta Aditya 2024 年 6 月 9 日
To resolve this issue, you can store arrays of different sizes in a cell array without concatenating them.

サインインしてコメントする。

回答 (1 件)

Arun
Arun 2024 年 6 月 20 日
Hi Shaifali,
I understand that you are looking to add groups of varying sizes to a cell array but are encountering the following error: “Error using vertcat: Dimensions of arrays being concatenated are not consistent.”
Below is a sample script that demonstrates how to add groups of different sizes to a cell array:
group1 = [1, 2, 3, 4]; % Group 1 with 4 users
group2 = [1, 2]; % Group 2 with 2 users
group3 = [1, 2, 3, 4, 5, 6]; % Group 3 with 6 users
% Adding each group to the cell array
userGroups{1} = group1;
userGroups{2} = group2;
userGroups{3} = group3;
% Dynamically adding user groups
newGroup = [4, 5, 3, 8];
userGroups{end + 1} = newGroup;
userGroups
userGroups = 1x4 cell array
{[1 2 3 4]} {[1 2]} {[1 2 3 4 5 6]} {[4 5 3 8]}
For more information related to cell array, please refer the following MATLAB documentation link: https://www.mathworks.com/help/matlab/cell-arrays.html
Hope this helps!
Regards
Arun

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by