在Matlab中扩展数组长度时出现错误

时间:2022-06-13 17:27:37

i have wrote a code but when i am trying to change the valuables, schedule(2,:) occurs error. my code:

我写了一个代码,但当我试图更改贵重物品时,时间表(2,:)发生错误。我的代码:

clc;clear;
a = [1 2 3 4];
N = 3;
schedule(1,:) = kron(a,ones(1,N));% repeat 4 days
schedule(2,:) = repmat([1 2 3],1,4); % repeat time slots in each day %nums col rep
schedule(3,:) = randperm(12); % randomize 12 courses
schedule

is a way to match length of schedule(2,:) with others? for example when length of other is 20, schedule(2,:) does not build more than 20. it's not standard.
thanx...

是一种方法来匹配日程安排(2,:)与其他人的长度?例如,当other的长度为20时,schedule(2,:)不会超过20,这不是标准的。感谢名单...

1 个解决方案

#1


When you change day and / or repeat the error occurs in

当您更改日期和/或重复时,会发生错误

schedule(2,:) = repmat([1 2 3],1,4);

because the size of the array generated by repmat([1 2 3],1,4) has always the same length while the length of the arrays generated by using kron and randperm changes according to the definiton of day and repeat.

因为由repmat([1 2 3],1,4)生成的数组的大小始终具有相同的长度,而使用kron和randperm生成的数组的长度根据日期和重复的定义而变化。

A possible solution could be to modify the instruction

可能的解决方案是修改指令

schedule(2,:) = repmat([1 2 3],1,4);

schedule(2,:) = repmat([1 2 3],1,4);

as follows:

schedule(2,:) = repmat([1:repeat],1,length(day))

This solution allows schedule(2,:) having the same length of schedule(1,:) and schedule(1,:).

该解决方案允许调度(2,:)具有相同的调度长度(1,:)和调度(1,:)。

Hope this helps.

希望这可以帮助。

#1


When you change day and / or repeat the error occurs in

当您更改日期和/或重复时,会发生错误

schedule(2,:) = repmat([1 2 3],1,4);

because the size of the array generated by repmat([1 2 3],1,4) has always the same length while the length of the arrays generated by using kron and randperm changes according to the definiton of day and repeat.

因为由repmat([1 2 3],1,4)生成的数组的大小始终具有相同的长度,而使用kron和randperm生成的数组的长度根据日期和重复的定义而变化。

A possible solution could be to modify the instruction

可能的解决方案是修改指令

schedule(2,:) = repmat([1 2 3],1,4);

schedule(2,:) = repmat([1 2 3],1,4);

as follows:

schedule(2,:) = repmat([1:repeat],1,length(day))

This solution allows schedule(2,:) having the same length of schedule(1,:) and schedule(1,:).

该解决方案允许调度(2,:)具有相同的调度长度(1,:)和调度(1,:)。

Hope this helps.

希望这可以帮助。