So Im given a .txt file which consists of number 1 to 10 with decimals and now im asked to make a table(sort of) for number between 9 to 10 and the counts of it then number 8 to 9 and so on. using logical operational and relational operators. How im suppose to link both of them??

댓글 수: 2

Geoff Hayes
Geoff Hayes 2015년 3월 29일
Victor - is this homework? Please clarify what you are expected to do with an example.
Victor Seaw
Victor Seaw 2015년 3월 29일
yes it is a homework im expected to use the .xtxt file to make a list in where range 9 to 10 showing how many 9 to 10 shown in the .txt file and range 8 to 9 showing how many 8 to 9 in the .txt file and so on till 0 to 1
example if the .txt file having 8.3 8.9 9.8 and so on then my range 9 to 10 should show 1 and range 8 to 9 should show 2

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

답변 (1개)

Star Strider
Star Strider 2015년 3월 29일

0 개 추천

This is one approach:
x = randi(1000, 1, 100)/100;
for k1 = 1:10
interval = [x > (k1-1) & (x <= k1)];
interval_sum(k1) = sum(interval);
end
% COMPARE WITH ‘histc’
binrng = [0:10];
hcounts = histc(x, binrng);
I will leave it to you to import your text file and change the code I posted to meet your requirements. (The comparison with the histc function is informational only to check the performance of the loop. It is not part of the code.)

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

질문:

2015년 3월 29일

답변:

2015년 3월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by