Insert two elements in a multidimensional array

7 ビュー (過去 30 日間)
Cesar Ramirez
Cesar Ramirez 2019 年 2 月 18 日
コメント済み: Cesar Ramirez 2019 年 2 月 18 日
Hi, I want to insert two elements (h1,h2) into my multi array called xh after its initialized all with zeros.
N = 50;
xh = zeros(2,N);
[h1,h2] = cruza(x(:,p1),x(:,p2));
%Insert h1 and h2 into xh
The function "cruza" returns elements to insert into xh
function [xh1,xh2] = cruza(xp1,xp2)
D=2;
pc = randi([1 D]);
xh1 = [xp1(1:pc) ; xp2(pc+1:D)];
xh2 = [xp2(1:pc); xp1(pc+1:D)];
  3 件のコメント
Cesar Ramirez
Cesar Ramirez 2019 年 2 月 18 日
Hi, for example h1 and h2 would have the next values.
h1 =
1.1604
-0.2671
h2 =
1.9483
-1.8290
And I want to insert them and replace the zeros at the vector xh.
madhan ravi
madhan ravi 2019 年 2 月 18 日
please explicitly state your desired output

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

採用された回答

per isakson
per isakson 2019 年 2 月 18 日
編集済み: per isakson 2019 年 2 月 18 日
Something like this?
%%
N = 50;
xh = zeros(2,N);
%% Insert h1 and h2 into xh
for jj = 1 : 2 : N
...
[h1,h2] = cruza(x(:,p1),x(:,p2));
xh(:,jj) = h1;
xh(:,jj+1) = h2;
end
  1 件のコメント
Cesar Ramirez
Cesar Ramirez 2019 年 2 月 18 日
thanks you so much.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by