0

I am trying t create an exact copy, duplicate, of an already created and populated array in Matlab. I grasp that I could just use a loop to copy all the fields, but isn't there an easier way?

The created array is an array of structs. My code so far is as follows.

Thank you for all your help in advance.

a = 1;
window = eye_record.x_pos_measured_deg; %zeros(length(eye_record));
disT = .50;

for i=1:length(eye_record)
    %window(i) = eye_record(i).x_pos_measured_deg;
    dis = (max(window(a:i)) - min(window(a:i)));
    if (dis <= disT)
        eye_record(i).xy_movement_EMD = 1;
        fixation_counter = fixation_counter + 1;
    else
        eye_record(i).xy_movement_EMD = 2;
        a = i;
        saccade_counter = saccade_counter + 1;
    end
end
0

1 Answer 1

2

If A is your already created array you can create an exact copy by assigning it to a new variable

>> B = A;

For example

>> A(1) = struct('Name', 'A');
>> A(2) = struct('Name', 'B');
>> B = A
B = 

1x2 struct array with fields:

    Name
>> B(1).Name
ans =

A
>> B(2).Name
ans =

B
Sign up to request clarification or add additional context in comments.

6 Comments

I think that is what is there? I get an error stating that the "Index exceeds matrix dimensions". How is that possible??
@user3534918 That is where? In your question? I don't see what you mean.
Sorry. I think that my code is doing what you suggested? I honestly am not certain though.
@user3534918 I am not certain. If you tell me what variables you are trying to copy I can help?
eye_record is the array of structs, I was hoping to be able to copy just the x_pos elements into window without having to use the loop. Does that help?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.