problem in creating an array
4 次查看（过去 30 天）
süleyman burak çelik ，2015-1-15
评论： süleyman burak çelik ，2015-1-17
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.
Youssef Khmou 2015-1-15
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 :
Find more on Operators and Elementary Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!