简体   繁体   English

在分配A(I)= B中,B和I中的元素数必须相同

[英]In assignment A(I) = B, the number of elements in B and I must be the same

I input 'test' as the string, phrase, and it gives me the following error: 我输入“ test”作为字符串,短语,这给了我以下错误:

    >> CreateBarcodePattern('test')
In an assignment  A(I) = B, the number of elements in B and I must be the same.

Error in CreateBarcodePattern (line 5)
    p(i) = code128B{find(ismember(code128B,phrase(i)))-109,3};

The function CreateBarcodePattern is as follows: 函数CreateBarcodePattern如下:

function [p] = CreateBarcodePattern(phrase)
load('code128B');
p = [];
for i = 1:length(phrase)
    p(i) = code128B{find(ismember(code128B,phrase(i)))-109,3};
end

I put a break point at line 5 and at the point i = 1, p = [] (and empty array so far), code128B = <108x3 cell> (A 108 by 3 cell full of strings), and phrase = 'test'. 我在第5行和i = 1处设置了一个断点,p = [](到目前为止是空数组),code128B = <108x3单元格>(一个由108个3单元格组成的充满字符串的字符串),短语='test '。 The very next line gives me the error above. 下一行给了我上面的错误。 I tried doing: 我试着做:

load('code128B.mat')
p = [];
phrase = 'test';
p(1) = find(ismember(code128B,phrase(1)))-109;
p(1) = code128B{p(1),3}

but at the last line the error: 但在最后一行错误:

In an assignment  A(I) = B, the number of elements in B
and I must be the same.

is again given. 再次给出。 Right before the error, p = 84 which is what I am expecting, this is due to the previous line, p(1) = fi... The line: 在错误之前, p = 84这是我期望的),这是由于上一行p(1) = fi...该行:

code128B{find(ismember(code128B,'t'))-109,3};

Returns the correct variable so I know this much works. 返回正确的变量,所以我知道这很有用。 It just doesn't work when I'm iterating it. 当我迭代它时,它不起作用。 How can I fix this? 我怎样才能解决这个问题?

Maybe the line 也许线

find(ismember(code128B,phrase(1)))

is returning more than 1 index. 返回多个索引。 p(1) wants exactly one element. p(1)只需要一个元素。

If you just want the first index, then do something like this: 如果您只想要第一个索引,请执行以下操作:

Idx = find(ismember(code128B,phrase(1)));
Idx = sort(Idx); % Am just assuming you need to sort!
p(1) = Idx(1) - 109;
p(1) = code128B{p(1),3}

I found the answer: 我找到了答案:

p(i) = code128B{find(ismember(code128B,phrase(i)))-109,3};
p(i) = str2num(code128B{find(ismember(code128B,phrase(i)))-109,3});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在分配A(I)= B中,B和I中的元素数必须相同 - In an assignment A(I) = B, the number of elements in B and I must be the same 赋值A(I)= B时出错,B和I中的元素数必须相同 - error with an assignment A(I) = B, the number of elements in B and I must be the same 在赋值A(I)= B中,B和I中的元素数必须相同 - In an assignment A(I) = B, the number of elements in B and I must be the same 马赛克:??? 在赋值 A(I) = B 中,B 和 I 中的元素个数必须相同 - MATLAB: ??? In an assignment A(I) = B, the number of elements in B and I must be the same 在赋值 A(:) = B 中,A 和 B 中的元素数量必须相同 - In an assignment A(:) = B, the number of elements in A and B must be the same 在赋值 A(:) = B 中,A 和 B 中的元素数量必须相同 - In an assignment A(:) = B, the number of elements in A and B must be the same 逻辑数组 - 在赋值A(I)= B中,B和I中的元素数必须相同 - Logical Arrays - In an assignment A(I) = B, the number of elements in B and I must be the same 不知道如何纠正:“在赋值A(I)= B中,B和I中的元素数必须相同。” - Don't know how to Correct : “In an assignment A(I) = B, the number of elements in B and I must be the same.” 如何解决:在分配A(I)= B中,B和I中的元素数必须相同 - How to solve: In an assignment A(I) = B, the number of elements in B and I must be the same 需要详细解释“在赋值A(I)= B中,B和I中的元素数必须相同” - Need detail explaination about “In an assignment A(I) = B, the number of elements in B and I must be the same”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM