how to set value for each column?

2 visualizaciones (últimos 30 días)
hana razak
hana razak el 26 de Oct. de 2017
Comentada: hana razak el 26 de Oct. de 2017
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

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 26 de Oct. de 2017
A = randi([25 50],15,10);
k = {'10','01'};
n = size(A,2);
k = k(ceil(2*(1:n)/n));

Más respuestas (1)

KSSV
KSSV el 26 de Oct. de 2017
Let A be your 15x10 matrix.
B = ones(size(A)) ;
B(:,1:5) = 10 ;
  1 comentario
hana razak
hana razak el 26 de Oct. de 2017
Thanks for your quick reply.
I've checked using your given code.It turns out to be 10(15x5) and 1(15x5).
I don't want to change each element of array A.
I need to appoint for each column from 1 to 5 to have the value of k = '10' and
each column from 6 to 10, to have the value of k = '01'.
In another way, I want it to be like this;
(:,1) -> k = 10
(:,2) -> k = 10
.
.
.
(:,5) -> k = 10
(:,6) -> k = 01
(:,7) -> k = 01
.
.
.
(:,10) -> k = 01
Do you have any idea to do it?
Thank you

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by