I am trying to store the results of a for loop in a cell array but I get the following error:
Cell contents assignment to a
non-cell array object.
Error in Untitled_2 (line 7)
C{x} = Noise_x;
Here is my code:
Image = imread('C:\Program Files\MATLAB\R2017a\bin\face.jpg');
imshow(Image);
C = zeros(1:10);
for x = 1:16
i = randn(1);
Noise_x = imnoise(Image,'gaussian',i);
C{x} = Noise_x;
end
imshow(C(1));
Thank you in advance.

 Réponse acceptée

C = zeros(1:10);
This defines C as a double class array with 10 dimensions.
C{x} = ...
This attempts to populate a cell class element of C array, but you receive an error because C is a double class array. You can fix this by changing your original definition of C.
C = cell(1); % This will create a 1x1 array of blank cells
Then you can just use your C{x} line that you already have to populate the desired values into cell x.

1 commentaire

Image = imread('C:\Program Files\MATLAB\R2017a\bin\face.jpg');
imshow(Image);
n = 16;
C_g = cell(n,1); 
for x = 1:n
i = randn(1);
Noise_x = imnoise(Image,'gaussian',i);
C_g{x} = Noise_x;
end

Now it's working. Thank you :)

Connectez-vous pour commenter.

Plus de réponses (1)

Rik
Rik le 27 Mar 2018
I suspect your should have looked something like this (note the commented lines and the comments)
%IM = imread('C:\Program Files\MATLAB\R2017a\bin\face.jpg');
%don't overwrite the image function
IM = imread('C:\Program Files\MATLAB\R2017a\bin\face.jpg');
imshow(IM);
%C = zeros(1:10);%creates a 10-D double array
C=cell(1,16);
for x = 1:16
i = randn(1);
Noise_x = imnoise(IM,'gaussian',i);
C{x} = Noise_x;
end
%imshow(C(1));%assumes C is a non-cell array
imshow(C{1});

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by