Add a certain row to each new row generated by same loop function ! HOW!

How can I add a certain row generated by a loop function to each new row generated by same loop function? Thanks in advance!
for k=1:1:100
for i=x1:1:x3
% x1<x2<x3
if i<x2
[a(i,k),b(i,k),c(i,k)]=function(input1(i),input2(k));
else
% this is my (certain) row (at i=x2) to be added
[a(x2,k),b(x2,k),c(x2,k)]=function(input1(i),input2(k))
% above row to be added to each row of below function:
[a(i,k),b(i,k),c(i,k)]=function(input1(i),input2(k));
end
end
end

1 件のコメント

James Tursa
James Tursa 2013 年 7 月 25 日
編集済み: James Tursa 2013 年 7 月 25 日
This is unreadable ... please use the "{} Code" button to format your code.

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

 採用された回答

Andrei Bobrov
Andrei Bobrov 2013 年 7 月 25 日
編集済み: Andrei Bobrov 2013 年 7 月 25 日

0 投票

input1 = randi([10 100],10,1); % Let your data
input2 = randi(9,10,1);
[j1 j2] = ndgrid(input1,input2);
[a ,b, c] = arrayfun(@(x,y)YourFunction1(x,y),j1,j2);

1 件のコメント

Horst Guenter
Horst Guenter 2013 年 7 月 25 日
編集済み: Horst Guenter 2013 年 7 月 26 日
Dear Andrei, first let me thank you for your proposal!
This workes now with a additionally defined handle funtion (Myfunction1) and only for two input arrays (I have arround 50)!
And, as I am using Myfunction1 first for creattion of the input arrays and then as the handle function, I would like to avoid defining the handle function seperately. And, I would like to preserve the intial variable names.
Is something like this possible?
Once again, I need to add scalar values resulting of Myfunction1(:,300) to all array elements resulting from Myfunction1.My result should look like this.
[a(k,i)+a(k,300),..,n(k,i)+n(k,300)]

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File 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