problem in creating an array

조회 수: 2 (최근 30일)
süleyman burak çelik
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
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 :
alfas=(acos((e.*cos(fis)-1)./(sqrt(e.^2-2.*e.*cos(fis)+1))));
  댓글 수: 1
süleyman burak çelik
süleyman burak çelik 2015년 1월 17일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by