Insert two elements in a multidimensional array

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

Let's suppose that N = 5 instead of 50. Then
xh = [0 0 0 0 0;
0 0 0 0 0]
What size are h1 and h2? (Please give an example of what they look like.) Where do you want to insert them into xh? How do we know that?
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.
please explicitly state your desired output

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

 채택된 답변

per isakson
per isakson 2019년 2월 18일
편집: per isakson 2019년 2월 18일

2 개 추천

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품

릴리스

R2017b

질문:

2019년 2월 18일

댓글:

2019년 2월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by