problem in creating an array

1 Ansicht (letzte 30 Tage)
süleyman burak çelik
süleyman burak çelik am 15 Jan. 2015
I have a simple problem, but I can't solve. I created an array naming as "alfas" given below. When the numbers of variables is more than one and when the code is run, in the command window, lz is an array, but alfas gives only one alfas value:
below code gives an array for alfas, there is no problem: clc; clear; clear all; lamda=0.1; k=2*pi/lamda; rho=3*lamda; a=0.5; e=3; fis=-pi:pi./100:pi; alfas=(acos((e.*cos(fis)-1)/(sqrt(e.^2-2.*e.*cos(fis)+1)))); alfas In command window, alfas is an array. it is OK.
But, when the code below is run, alfas gives only one result in command window:
clc; clear; clear all; lamda=0.1; k=2*pi/lamda; rho=3*lamda; a=0.5; e=3; fis=-pi:pi./100:pi; lz=((a.*(e.^2-1))./(e.*cos(fis)-1)); alfas=(acos((e.*cos(fis)-1)/(sqrt(e.^2-2.*e.*cos(fis)+1))));
lz % it is an array , alfas % it gives only one result that is equal to 2.0495
in Command window, alfas=2.0495 (only one result)
Why cannot I see an array for alfas in this situation, I cannot understand. If anybody could help me, I will be very happy. Thank you very much.

Akzeptierte Antwort

Youssef  Khmou
Youssef Khmou am 15 Jan. 2015
The reason the output is scalar is because you divide a vector by vector like in this example rand(1,4)/rand(1,4), to return an array you need to use element wise operation rand(1,4)./rand(1,4), to fix this problem in your example try :
alfas=(acos((e.*cos(fis)-1)./(sqrt(e.^2-2.*e.*cos(fis)+1))));
  1 Kommentar
süleyman burak çelik
süleyman burak çelik am 17 Jan. 2015
Upsss! Thank you very much.. I supposed that I added dot(.) everywhere in the equation, but you showed me that I missed dot (.) there... Thank you very much again.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by