フィルターのクリア

How do I write a for loop for repeatable division algorithm?

2 ビュー (過去 30 日間)
want2know
want2know 2014 年 2 月 17 日
コメント済み: want2know 2014 年 2 月 18 日
Hi all,
"a" contains index, Vb contains values
for example,
inputs: vref= 20 a=[2 4 6 9] Vb=[ 8 9 1 7 5 3 6 55 8 7]
output: (9 plus with 1 gives 16) sum_Bank1 = 16
What I want to do:
If sum_Bank1 is greater than vref, i want the system to divide Bank1 into half again, and check if sum_Bank3 is still greater than vref, if it is, Bank3 is divided by half again, this process is repeated for many times until certain condition.
My question is, how can I write it in a loop instead of repeat the same codes many times?
function [sum_Bank1] = division(a, vref)
dimen = size (a);
ncol = dimen (2); % ncol=4
Bank1= a(:, 1:ncol/2); % Bank1 = [2 4]
Bank2= a(:, ((ncol/2) + 1):ncol); % Bank2 = [6 9]
sum_Bank1=sum(Vb(Bank1)); % sum_Bank1 = 16
sum_Bank2=sum(Vb(Bank2)); % sum_Bank1 = 11
if sum_Bank1 > vref
Bank3= Bank1(:,1:ncol/2);
Bank4= Bank1(:, ((ncol/2) + 1):ncol);
if sum_Bank3 > vref
Bank5= Bank3(:,1:ncol/2);
Bank6= Bank3(:, ((ncol/2) + 1):ncol);
if sum_Bank5 > vref
Bank7= Bank5(:,1:ncol/2);
Bank8= Bank5(:, ((ncol/2) + 1):ncol);
  1 件のコメント
want2know
want2know 2014 年 2 月 18 日
anyone please? just an idea perhaps?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by