필터 지우기
필터 지우기

How to get the two outputs from "function"

조회 수: 2 (최근 30일)
PVR
PVR 2016년 1월 18일
댓글: Image Analyst 2016년 1월 18일
I have the below code which needs to provide both nodes and connectivity matrices. The formulation and for-loop is all correct I believe but I'm only getting the nodes matrix but not the connectivity matrix. If I remove the semicolon after connectivity(:,i) = [p,q], I'm getting matrices for all the iterations. All I need is the output to have final nodes and connectivity matrices like in the image attached. I'm using a N value of 6 and R value of 1. It's easy I believe but I'm not thinking straight. Help much appreciated. Thank you!
function [nodes, connectivity] = stat(N, R)
nodes = zeros(2,N);
connectivity = zeros(2,N);
for i=1:N
a = (360/N)*(pi/180)*(i-1);
x = R*cos(a);
y = R*sin(a);
nodes(:,i) = [x;y];
p = i;
q = i+1;
if q>N
q=1;
end
connectivity(:,i) = [p;q];
end
end
  댓글 수: 2
Mohammad Abouali
Mohammad Abouali 2016년 1월 18일
On my system your function gives back both nodes and connectivity:
[nodes, connectivity] = stat(10, pi)
nodes =
3.1416 2.5416 0.9708 -0.9708 -2.5416 -3.1416 -2.5416 -0.9708 0.9708 2.5416
0 1.8466 2.9878 2.9878 1.8466 0.0000 -1.8466 -2.9878 -2.9878 -1.8466
connectivity =
1 2 3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9 10 1
PVR
PVR 2016년 1월 18일
I only got nodes as output, that too it doesn't say nodes, it says "ans". Can you help me if there's some change in settings to get the output like yours.

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

채택된 답변

Walter Roberson
Walter Roberson 2016년 1월 18일
I suspect you are not invoking it correctly. Be sure to use two outputs when you call it:
[n, c] = stat(N, R)
  댓글 수: 2
PVR
PVR 2016년 1월 18일
You mean in the end?
Image Analyst
Image Analyst 2016년 1월 18일
Huh? What "end"? In your main program stat calls stat() of course. You're probably doing
stat(N, R)
and not
[n, c] = stat(N, R)
like Walter said.

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

추가 답변 (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