如何在Matlab中创建重复数组 [英] How to create a duplicate array in Matlab

查看:835
本文介绍了如何在Matlab中创建重复数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Matlab中创建一个已经创建并填充的数组的精确副本.我知道我可以只使用循环来复制所有字段,但是难道没有更简单的方法吗?

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.

谢谢您的所有帮助.

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

推荐答案

如果A是您已经创建的数组,则可以通过将其分配给新变量来创建精确副本

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

>> B = A;

例如

>> 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

这篇关于如何在Matlab中创建重复数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆