필터 지우기
필터 지우기

Writing an algorithm into Matlab syntax

조회 수: 1 (최근 30일)
Lovinash
Lovinash 2012년 9월 7일
Hello all,
I am trying to write the following algorithm into Matlab. Can someone please help me with putting this into Matlab syntax? Thanks. Lovinash
countA = 0
countB = 0
countC = 0
Import "C:\\Test.xlsx", "Sheet1", "A1:B730" as an array or matrix called 'L'
Define A as an array or matrix
Define B as an array or matrix
Define C as an array or matrix
for i from 1 to 99 do
x := L[i, 1]; (X = value in row i and column 1 of L)
y := L[i, 2]; (Y = value in row i and column 2 of L)
if 0<= y < 25 then
countA = countA+1
Include x and y to Array/Matrix 'A'
else if 25<= y <60 then;
countB := countB+1;
Include x and y to Array/Matrix 'B'
else if 60<= y then;
countC := countC+1
Include x and y to Array/Matrix 'C'
end if;
end do :
Print countA;
Print countB;
Prinnt countC;
Export array A to file "C:/Maple/A.xlsx" (and create the file)
Export array B to file "C:/Maple/B.xlsx" (and create the file)
Export array C to file "C:/Maple/C.xlsx" (and create the file)
  댓글 수: 1
Jan
Jan 2012년 9월 9일
Why didn't you try to implement this by yourself? If your argument is, that you do not know Matlab, posting code here would have an important drawback: You would not be able to debug the code. Therefor I'd suggest to learn Matlab a little bit, try to implement your program, post it here and use the suggestions to improve your code and your Matlab skills.

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

답변 (1개)

Rick Rosson
Rick Rosson 2012년 9월 7일
편집: Rick Rosson 2012년 9월 7일
Here is a start:
count = zeros(3,1);
L = xlsread('C:\\Test.xlsx','Sheet1','A1:B730');
N = 99;
x = L(1:N,1);
y = L(1:N,2);
idx = ( 0 <= y & y < 25 );
count(1) = sum(idx);
A = [ x(idx) y(idx) ];
Does that help? Do you understand what each line of code is doing? Can you figure out how to do the rest on your own?
To print the results, please review:
>> doc disp
and
>> doc fprintf
To export the data to Excel, please review:
>> doc xlswrite
Rick

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by