【发布时间】:2018-02-14 14:12:48
【问题描述】:
我有这个数组:
AB01 4 7
AB02 3 4
AB02 2 4
AB03 9 5
AB01 3 3
AB04 3 2
AB05 4 1
AB03 4 1
AB05 3 4
AB04 1 5
我有 2 个数字输入,它们确定最小值和最大值。例如,如果我设置第一个输入n1 = 2 和第二个输入n2 = 4,这意味着我想要在第一列中具有AB02、AB03 或AB04 值的行,我将得到如下输出这个:
AB02 3 4
AB02 2 4
AB03 9 5
AB04 3 2
AB03 4 1
AB04 1 5
我不知道如何从AB02-AB04 创建范围值,因为它不是一个数字。非常感谢您的帮助。
编辑:我正在尝试使用此脚本,我知道我的逻辑索引不正确,但我被卡住了。
col1 = 3;
fmt = repmat('%s',1,col1);
enter cofid = fopen('Document2.txt', 'rt');de here
filecolumn = textscan(fid, fmt, 'Delimiter', ' ');
fclose(fid);
FF = horzcat(filecolumn{:});
y1 = input('INPUT1: ')
y = sprintf('AB%.2d',y1)
z1 = input('INPUT2: ')
z = sprintf('AB%.2d',z1)
for o = y:z
while o == 1
index = find(strcmp(FF,o))
end
ff = FF(index,:)
end
【问题讨论】:
-
这个问题可以分成不同的子问题:(1)从字符串中提取一个数字(2)数组中元素的范围检查(3)逻辑索引
标签: arrays string matlab indexing