フィルターのクリア

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 Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by