Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Matlab:将一个单元格乘以一个向量_Arrays_Matlab_Cell - Fatal编程技术网

Arrays Matlab:将一个单元格乘以一个向量

Arrays Matlab:将一个单元格乘以一个向量,arrays,matlab,cell,Arrays,Matlab,Cell,我现在这样做: x1 = {...}; %a 1xn cell with each element being a column vector w = [...]; %some column vector result = zeros(n,1); % now I want to multiply each vector in x by w for i = 1:n result(i) = w'*cell2mat(x1(i)); end 这当然是可行的,但Matlab背后的想法是利用它的优

我现在这样做:

x1 = {...}; %a 1xn cell with each element being a column vector
w = [...]; %some column vector
result = zeros(n,1);

% now I want to multiply each vector in x by w

for i = 1:n
  result(i) = w'*cell2mat(x1(i));
end

这当然是可行的,但Matlab背后的想法是利用它的优化向量和矩阵乘法等。所以我认为我可能做错了什么。有没有更好的方法来实现上述性能方面的功能?

我认为您可以用以下方法来代替for循环:

result = w'*cell2mat(x1);

我认为您可以将for循环替换为:

result = w'*cell2mat(x1);

或者,您可以使用

result = cellfun(@(x) w'*x,x1);

尽管我认为另一个答案会更快。

或者你可以使用

result = cellfun(@(x) w'*x,x1);

尽管我认为另一个答案会更快。

谢谢,这正是我想要的。如果是,请单击投票箭头下方的勾号接受答案。谢谢,这就是我想要的。如果是,请单击投票箭头下方的勾号接受答案?