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.

1 vue (au cours des 30 derniers jours)
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

Réponses (1)

Vedant Shah
Vedant Shah le 28 Avr 2025
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 fromnet, 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:

Catégories

En savoir plus sur Performance and Memory dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by