# Can't sort this code

조회 수: 2 (최근 30일)
Tom 2012년 1월 25일
The original question has been removed by the user.
##### 댓글 수: 4이전 댓글 2개 표시이전 댓글 2개 숨기기
Jan 2012년 1월 26일
Please take the time to formulate a complete question. Currently it is not clear, what the program does, if it fails or not, if it creates the wanted results, or if not, what the dfferences between the results and your expectations are.
Tom 2012년 1월 26일
Okay yeah sorry, I'll try to bear that in mind.

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

### 채택된 답변

Dr. Seis 2012년 1월 26일
You define fnj as MxN, but in your for loop you are assigning values to fnj(j,n) where:
j = 1 : N
and
n = 1 : M
I think you meant to do "j = 1 : M" and "n = 1 : N"
Also make the change suggested by proecsm, namely
Fn = sum(fnj,2)
##### 댓글 수: 2없음 표시없음 숨기기
Tom 2012년 1월 26일
Yeah I think that was like that because I couldn't get my head around which way round j and n were supposed to go - plus I wanted to see if I'd get the right plot by switching them. J does have to go to N though and n goes to M for sure. I've swapped fnj(j,n) for fnj, n,j). I'll explain a bit more about this in an answer.
Dr. Seis 2012년 1월 26일
If you swap fnj(j,n) for fnj(n,j) - make sure you get both -, then you don't need to make the change to sum. Leave it as "Fn = sum(fnj);"

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

### 추가 답변 (2개)

bym 2012년 1월 26일
You do not have 2 lines on the graph: it goes from left to right & back again. After some noodling, I think you want to replace
Fn = sum(fnj);
%plot(AnRec,Fn)
pn = Fn*(M./(ar*N));
plot(xjRec,pn,'LineWidth',1.7)
with the following, which makes more sense (or at the very least presents more pleasing plots :) )
Fn = sum(fnj,2);
plot(AnRec,Fn)
figure
pn = Fn*(M./(ar*N));
plot(xjRec,pn,'LineWidth',1.7)
##### 댓글 수: 2없음 표시없음 숨기기
Tom 2012년 1월 26일
Thanks - so what does the added ',2' do?
Dr. Seis 2012년 1월 26일
Adding the 2 will sum all the values in a row.

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

Tom 2012년 1월 26일
I have this as a similar problem, which I can use as a kind of template for this one...
'1024 samples of one period of a 1Hz sine wave are taken. By analysing the amplitude range from – 10 Pa to 10 Pa in 60 equal segments, estimate the probability density function of the sine wave.'
The solution is here - http://dl.dropbox.com/u/11341635/Tut10-11SolQ2.png No built in Matlab functions allowed!
It's basically sampling the old-fashioned way - creating an array of static amplitude points as a framework for the receiving part of the system. The incoming signal is sampled at a given sampling frequency, and each sample received by the system will be analysed to see which amplitude point to match it up to - hence the two FOR loops, with an IF in the middle. One FOR loop is to consider each sample one at a time, and the other FOR loop is to determine whether each incoming sample in close to the amplitude point at hand. If it is, a value of 1 is placed in the 2-D matrix, the size of which is determined by the no. of amplitude points and the sampling frequency.
Phew.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Dr. Seis 2012년 1월 27일
See comment above.

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

### 카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by