Vector operatin in Matlab

Hi,
I have to programme a proccess but I don't know how to do it.
I have a vector called 'x' :
X= 1 2 3 4 5 6
On the other hand, another called y (related with x).
Y= 0.1 0. 3 0.4 0.8 0.3 0.5
Then, I have another table that also is from 1 to 6 (the x vector is the same). But this table has only numbers in the 5, 6 and 7th position.
Y1= - - - 0.2323 0.25656 0.8
I need to create one new vector that multiply the y values with the y1 but I don't know how to do it in Matlab.
Greetings and thanks a lot in advance,

2 commentaires

Jan
Jan le 31 Juil 2012
The vector does not have a 7th position, because it has 6 elements only.
Please explain this sentence again, what are you needing exactly. "Creating a new vector that multiply y with y1" is not sufficient to understand, what you want to achieve. I cannot imagine, what the "-" in the vector should be.
klipya
klipya le 1 Août 2012
Modifié(e) : klipya le 1 Août 2012
Thanks Jan for your reply. Yes, you are right, it only has 6 elements, sorry. The '-' element, mean that there aren't any value there. So, for example: I need that the code multiply, on one hand, 6(x)*0.5(y) and, on the other hand, also 6*0.8(y1). And then I need multiply the result of both elements. On the first position I need:
1(x)*0.1(y1) and 1*nothing (becaure there aren't any value, so I need a '0' result).
Why I'm doing this? Because I have one vector called x, one another called y and the last one, y1. And I need that the y1 don't do 1*0.2323 because it's not on the same position (it has to be 1* 0 because there aren't any position).
I don't know if I'm explaining well. I hope yes! Thanks a lot! ;)
Pd) I can't not do it if the size of the vectors are different?

Connectez-vous pour commenter.

 Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 30 Juil 2012
Modifié(e) : Andrei Bobrov le 1 Août 2012

0 votes

Y= [0.1 0.3 0.4 0.8 0.3 0.5];
Y1 = [0.2323 0.25656 0.8];
out = [zeros(1,numel(Y1)-numel(Y)),Y].*[zeros(1,numel(Y)-numel(Y1)),Y1];

6 commentaires

klipya
klipya le 31 Juil 2012
Thanks a lot Venkat and Andrei!
Andrei, I get the next error: "Matrix dimensions must agree." I don't know how to solve it. I understand that it's because of the different structure of the vectors.
Andrei Bobrov
Andrei Bobrov le 1 Août 2012
My answer was corrected.
klipya
klipya le 1 Août 2012
Thanks a lot! It works!
klipya
klipya le 1 Août 2012
Modifié(e) : klipya le 1 Août 2012
Hi Andrei!
Thanks a lot for your message, it helps me a lot! I have tried with my vectors. But I have a lot (more than 2500) and I need to “start” in line 350 but I get this mistake (I also have checked the size and it’s the same):
??? Error using ==> horzcat CAT arguments dimensions are not consistent.
Do you know what can I do? Thanks a lot!
Greetings,
Andrei Bobrov
Andrei Bobrov le 2 Août 2012
Please give simple numeric example
klipya
klipya le 3 Août 2012
This is what I've done:
graf=0; for p=(101:180) graf(p)=out1_c; end for p=(171:240) graf(p)=out2_c; end
And I create the document Y1 with O in the places that I don't need and it works.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Language Fundamentals dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by