vector into matrix and loop over different length vectors.

1 visualización (últimos 30 días)
Mikkel
Mikkel el 10 de Mzo. de 2016
Respondida: Geoff Hayes el 11 de Mzo. de 2016
Hey Matlab experts
I have a vector (Ekstrem.peak_wave_direction) which consists of degrees that where measured at an observation for wave direction. I want to find their index from the different positions and insert that into the corrosponding (Ekstrem.sign_wave). So I find at i = 1 angles_1 = 0 and angles_2 = 10. Which gives me all the directions between those. This I can do.
My problem is that I want to create a vector consisting of the directions pr 10 degrees which in a cirkle will give me 36 vectors. I want to couple them together so when i e.x. type wave_dir(1) it gives me the first vector which is a 1x200, and represent 0 - 10 degres. My wave_dir(2) would give me the direction of 10-20 degrees, but this is a 1x154 vector. And as I understand you cant add two vectors together with different length? If you can please tell me.
Since I didnt know how to program it, I thought of creating a zero matrix that was big enough to have the biggest vector in it, and then also adding the others.
But how do I add a vector column to the first column in a matrix?
My example is:
M = zeros(30000,36);
Index1 = rand(15000,1);
Index2 = rand(20000,1);
How do I get those vectors in the first and second column?
The other code is for the loop Im trying to create.
Hope someone can help me.
angles_1 = 0:10:350;
angles_2 = 10:10:360 ;
index = [];
for i = 1:length(angles_1);
index(i) = find(Ekstrem.peak_wave_direction >= angles_1(i) & Ekstrem.peak_wave_direction < angles_2(i));
wave = Ekstrem.sign_wave(index);
end

Respuestas (1)

Geoff Hayes
Geoff Hayes el 11 de Mzo. de 2016
Mikkel - perhaps you can use a cell array to manage all the directions. Each element in the cell array can be a vector, and each vector need not be the same size as any other. For example,
angles0To10 = rand(200,1);
angles11To20 = rand(154,1);
wave_dir = cell(36,1);
wave_dir{1} = angles0To10;
wave_dir{2} = angles11To20;

Categorías

Más información sobre Matrix Indexing 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