Matlab 如何将每个结果作为向量?

Matlab 如何将每个结果作为向量?,matlab,Matlab,我想我总是遇到同样的问题,向量、数组和单元数组,通过这次讨论,我可以解决我的第一个问题。然而,我仍然需要数据中的每个结果都必须是e向量才能对其进行加密 fid = fopen('file.txt', 'r'); alldata = textscan(fid, '%s'); tmp = reshape(alldata{1}, 16, []).'; tmp = arrayfun(@(x)strjoin(tmp(x,:)), 1:size(tmp, 1), 'uniformoutput', false

我想我总是遇到同样的问题,向量、数组和单元数组,通过这次讨论,我可以解决我的第一个问题。然而,我仍然需要数据中的每个结果都必须是e向量才能对其进行加密

fid = fopen('file.txt', 'r');
alldata = textscan(fid, '%s');
tmp = reshape(alldata{1}, 16, []).';
tmp = arrayfun(@(x)strjoin(tmp(x,:)), 1:size(tmp, 1), 'uniformoutput', false)
key=hex2dec(key_hex).'
data= (cat(1, tmp{:}))

for i= 1:rows(data)
  Matrix(i, :)= hex_keys([data(i,1:15), data(i,16)])
  chiffrement (Matrix(i,:), key,1)
endfor

endfunction
我的错误是:错误:纯文本必须是包含16个元素的向量(而不是单元格数组)。 如果你能帮助我,我将非常感激

例如,file.txt包含以下内容:

60 3d eb 10 15 ca 71 be 2b 73 ae f0 85 7d 77 81 60 3d eb 10 15 ca 71 be 2b 73 ae f0 85 7d 77 81 60 3d eb 10 15 ca 71 be 2b 73 ae f0 85 7d 77 81

事实上,这是一个大程序和函数序列,我所需要的就是如何将数据结果中的每一行转换为向量

data =

60 3d eb 10 15 ca 71 be 2b 73 ae f0 85 7d 77 81
60 3d eb 10 15 ca 71 be 2b 73 ae f0 85 7d 77 81
60 3d eb 10 15 ca 71 be 2b 73 ae f0 85 7d 77 81

我认为您的问题过于复杂,我的假设是您希望将
file.txt
中的数据转换为数字(即,您使用了
hex2dec
),因此,让我们这样做,并将Arrayfun排除在问题之外:

fid = fopen('file.txt', 'r');
alldata = textscan(fid, '%s');
tmp = reshape(alldata{1}, 16, []).'; % here we still parse 16 hex for every row using your function call
tmp = cellfun(@hex2dec,tmp,'un',0) % now we use cellfun to convert all your hex to numbers
Matrix = cell2mat(tmp)

Matrix =

96    61   235    16    21   202   113   190    43   115   174   240   133   125   119   129
96    61   235    16    21   202   113   190    43   115   174   240   133   125   119   129
96    61   235    16    21   202   113   190    43   115   174   240   133   125   119   129

whos Matrix

Name        Size            Bytes  Class     Attributes

Matrix      3x16              384  double        

现在,您可以使用for循环执行任何您想执行的操作,它将成为常规索引。

我认为您将问题复杂化了,我的假设是您希望将
文件.txt中的数据转换为数字(即,您使用了
hex2dec
),因此,让我们这样做,让Arrayfun远离问题:

fid = fopen('file.txt', 'r');
alldata = textscan(fid, '%s');
tmp = reshape(alldata{1}, 16, []).'; % here we still parse 16 hex for every row using your function call
tmp = cellfun(@hex2dec,tmp,'un',0) % now we use cellfun to convert all your hex to numbers
Matrix = cell2mat(tmp)

Matrix =

96    61   235    16    21   202   113   190    43   115   174   240   133   125   119   129
96    61   235    16    21   202   113   190    43   115   174   240   133   125   119   129
96    61   235    16    21   202   113   190    43   115   174   240   133   125   119   129

whos Matrix

Name        Size            Bytes  Class     Attributes

Matrix      3x16              384  double        

现在,您可以使用for循环执行任何您想执行的操作,它将成为常规索引。

能否为问题添加一些数据?一个小小的file.txt会让洛蒂觉得我们需要更多的信息来帮助你。请添加ley_hex、函数hex_键和chiffrement。错误是在哪个函数中发生的?请查看编辑后的问题。能否为问题添加一些数据?一个小小的file.txt会让洛蒂觉得我们需要更多的信息来帮助你。请添加ley_hex、函数hex_键和chiffrement。错误发生在哪个函数中?请参见编辑的问题。