how to create matrix with multiple column vectors?

조회 수: 2 (최근 30일)
prabhabathi devi chandrasekaran
prabhabathi devi chandrasekaran 2018년 2월 21일
편집: Pawel Jastrzebski 2018년 2월 21일
I have to create channel matrix for 16 users. each column contains information about channel of particular user.my matrix size will be 128x16
  댓글 수: 3
prabhabathi devi chandrasekaran
prabhabathi devi chandrasekaran 2018년 2월 21일
No, not like that. I have combine all 128x1 column vectors into single matrix for further implementation.I found the answer thanks for your response.
Stephen23
Stephen23 2018년 2월 21일
"I have combine all 128x1 column vectors into single matrix for further implementation"
Storing them in one array right from the very beginning would be simpler, neater, and more efficient: most like this could be achieved using some basic indexing. Keep data together as much as possible always makes processing that data simpler.

댓글을 달려면 로그인하십시오.

답변 (1개)

Pawel Jastrzebski
Pawel Jastrzebski 2018년 2월 21일
편집: Pawel Jastrzebski 2018년 2월 21일
Regarding 'information about channel of particular user':
  1. Is it all numerical values?
  2. Is it mixed data i.e. channel 1 holds a number and channel two a text?
In case 1, you can use a solution as simple as matrix or table to store your information.
Consider the following example:
NoOfUsers = 16;
NoOfChannels = 128;
% 1) MATRIX
% create an empty matrix
M_UserChannel(NoOfChannels,NoOfUsers) = 0;
% 2) TABLE
T_UserChannel = array2table(M_UserChannel);
% CREATE COLUMN NAMES and ROW NAMES
% preallocate memory for the user names
users{1,NoOfUsers} = [];
for i=1:NoOfUsers
users{1,i} = ['user' num2str(i)];
end
clear i;
% preallocate memory for the channel names
rows{1,NoOfChannels} = [];
for i=1:NoOfChannels
rows{1,i} = ['channel' num2str(i)];
end
T_UserChannel.Properties.VariableNames = users;
T_UserChannel.Properties.RowNames = rows;
clear i rows users;
If the data is mixed, you can still use Matlab's table to store the information, on condition that:
  • Users are stored in rows
  • Channel information is stored in column (as columns within one table can hold data of various types - as long as you stick to one data type per column)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by