how to set value for each column?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I have an array of 15x10. The first half is pData and the second half is nData. How to set the data in order to get this condition;
1. Each column in 'nData' should have k = '01'
2. Each column in 'pData' should have k = '10'
Here are the data.
26 30 33 36 30 29 28 26 26 27
26 28 30 39 31 28 29 25 29 26
29 32 30 42 32 32 32 26 33 24
30 33 31 43 32 33 33 26 34 24
27 33 37 41 35 31 31 29 30 30
26 35 37 43 33 30 30 29 30 32
23 37 33 40 32 27 32 29 31 34
21 38 32 39 32 27 33 29 32 35
32 28 26 27 26 27 26 27 29 27
36 31 27 29 30 30 30 31 31 30
34 30 28 28 28 30 30 35 30 31
33 29 29 28 27 29 30 36 30 32
30 27 27 26 26 26 25 28 31 27
34 30 30 26 27 30 27 32 34 31
34 27 30 25 28 32 28 36 32 29
This is how I write to divide the array and to treat each column as above condition.
for i = 1:length(data)
for n_data = data(:,6:10,1)
k(i) = 01;
end
for p_data = data(:,1:5,1)
k(i) = 10;
end
end
This code doesn't give the expected results as below,
k
10 10 10 10 10 01 01 01 01 01
Please help me to solve this problem. Thank you
Hana
댓글 수: 0
채택된 답변
Andrei Bobrov
2017년 10월 26일
A = randi([25 50],15,10);
k = {'10','01'};
n = size(A,2);
k = k(ceil(2*(1:n)/n));
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!