필터 지우기
필터 지우기

How can I plot this equation? keep getting ??? Error using ==> mtimes Inner matrix dimensions must agree.'

조회 수: 1 (최근 30일)
The code I have is:
T=[0:0.1:24];
omega=((12-T)/24)*360;
phi=[-180:1:180]
alpha = [0:1:90];
latitude=45;
delta=[-23.5:0.5:23.5];
sind(alpha)=sind(delta).*sind(latitude)+cosd(delta).*cosd(latitude).*cos(omega)
cosd(phi)=(sind(alpha).*sind(latitude)-cosd(delta))./(cosd(alpha).*cosd(latitude))
alpha represents my y-axis and is an angle between 0 and 90 degrees. phi represents my x-axis and is an angle between say -120 to +120.
Whenever I try to input that last line I get the error stating inner matrix dimensions must agree. So I tried to reshape my matrices for those variables I defined so that they work. But then I get '??? ??? Subscript indices must either be real positive integers or logicals.'
It seems very tedious to have to reshape my matrix every time I define a new set of variables in order to use them with an equation. Those variables are used for defining my axis range, is there a better way I can lay them out or an automatic command that will make sure they work every time?
I want to plot alpha and phi as a graph using something like
plot(alpha,phi)
but can't get past those errors? can't I just use a command that says something like define x-axis [0:90], define y-axis [-120:120] or something?
Thanks

채택된 답변

David Sanchez
David Sanchez 2013년 10월 16일
Define your variables with linspace:
T=linspace(0,24,100);
omega=((12-T)/24)*360;
phi=linspace(-180,180,100);
alpha = linspace(0,90,100);
latitude=45;
delta=linspace(-23.5,23.5,100);
You'll get the same number of elements on each array. Your:
sind(alpha)=sind(delta).*sind(latitude)+cosd(delta).*cosd(latitude).*cos(omega);
cosd(phi)=(sind(alpha).*sind(latitude)-cosd(delta))./(cosd(alpha).*cosd(latitude));
are incongruently defined. What do you really want, alpha or sind(alpha)? why do you define alpha and phi as you did in
phi=linspace(-180,180,100);
alpha = linspace(0,90,100);
?
Do you want something like this?
alpha=sind(delta).*sind(latitude)+cosd(delta).*cosd(latitude).*cos(omega);
phi=(sind(alpha).*sind(latitude)-cosd(delta))./(cosd(alpha).*cosd(latitude));
plot(alpha,phi,'.')
  댓글 수: 1
P
P 2013년 10월 17일
Thanks. I tried using linspace but opted to use a for loop instead for my plot, which seems to have worked better. Thank you.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 10월 16일
omega is 1 by 241 while latitude is 1 by 95 so they're not the same number of elements so you can't do an element-by-element sum or product.
  댓글 수: 2
P
P 2013년 10월 16일
Yes I understand that my matrices need to be the same and I can see my error. I guess my question is then: is there a way I can generate my matrices to be the same dimensions from the start so that I don't have this problem but so that they are still for the applicable range of value I need for each variable? I.e 0-90 degrees for an angle and 0-24 hours for time? Any hell is greatly appreciated.
Image Analyst
Image Analyst 2013년 10월 16일
You can use linspace(startingValue, endingValue, numberOfElements) instead of startingValue : stepValue : endingValue to get exactly the number of elements you want.

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

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by