Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 7-by-1.
2 次查看(过去 30 天)
显示 更早的评论
Hello i have this problem
for i=1:341
for j=1:685
%y=net(x)
tst=reshape(inp_image(i,j,:),[1,10]);
y(i,j)= net(double(tst'));
end
end
0 个评论
回答(1 个)
Vedant Shah
2025-4-28
Assuming that it is desired that the function ‘net’ returns a 7-by-1 array, there are several ways to assign its output to ‘y’, depending on the desired outcome:
3D Array Storage:
To store all outputs from ‘net’, define ‘y’ as a 3D array with dimensions ‘[341, 685, 7]’. This allows storage of the full 7-element output vector for each ‘(i,j)’ pair. To achieve this, replace:
y(i,j)= net(double(tst'));
with
y(i, j, :) = net(double(tst'));
2D Array Storage (Single Value):
If only a single value from the output is required (such as the first element or the sum of all elements), extract the relevant value and assign it to a 2D array `y` of size `[341, 685]`. For example, replace:
y(i,j)= net(double(tst'));
with
out = net(double(tst'));
y(i, j) = sum(out);
Cell Array Storage:
To keep ‘y’ as a 2D structure while storing all 7 elements for each ‘(i, j)’, use a cell array of size ‘[341, 685]’, where each cell contains a 7-by-1 vector. First, declare ‘y’ as follows:
y = cell(341, 685);
Then, replace:
y(i,j)= net(double(tst'));
with
y{i, j} = net(double(tst'));
The most suitable approach can be selected based on the specific requirements of the application and the intended use of the `net` function's output.
For more information, you can refer to the following documentation:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!