how to fix subscripted assignment dimention mismatch in my coding?

clc;
clear all;
close all;
%%input images
im1 = imread('31-0000.jpg') ;
im2 = imread('32-0000.jpg') ;
im3 = imread('33-0000.jpg') ;
im4 = imread('34-0000.jpg') ;
im5 = imread('35-0000.jpg') ;
im6 = imread('36-0000.jpg') ;
im7 = imread('37-0000.jpg') ;
im8 = imread('38-0000.jpg') ;
M(:,:,1) = im1 ;
M(:,:,2) = im2 ;
M(:,:,3) = im3 ;
M(:,:,4) = im4 ;
M(:,:,5) = im5 ;
M(:,:,6) = im6 ;
M(:,:,7) = im7 ;
M(:,:,8) = im8 ;
hf2 = figure ;
hs = slice(M,[],[],1:8) ;
shading interp
set(hs,'FaceAlpha',0.8);
all images are of dimentions 250x306

2 comentarios

I've formatted your code today. Please use the buttons for formatting in the future. Thanks.
If you post a copy of the complete error message, the readers do not have to guess, where the problem occurs.
thankyou jan. i didn't know how to post the coding. will learn them in furure questions.

Respuestas (1)

The posted code works as expected. Please confirm, that this causes the same problem:
M = rand(250, 306, 8);
hs = slice(M,[],[],1:8) ;
shading interp
set(hs,'FaceAlpha',0.8)
If this does not create the same problem, the difference must be found inside te assignment of M:
M(:,:,1) = im1 ;
M(:,:,2) = im2 ;
...
Either the assumption is wrong, that "all images are of dimentions 250x306". Or the images are RGB images with the dimension [250 x 306 x 3].

7 comentarios

i have converted images into grayscale(some were already in gray).
now, it shows different error.
i tried to resize all images to 25x50Capture.JPG
Please post the full code. Now your M is not a single or double, so I guess, that you have converted the image data to uint8. Without seeing the code, I can only guess, what is going on.
clc;
clear all;
close all;
%%sample images
im1 = imread('31-0000.jpg') ;
im2 = imread('32-0000.jpg') ;
im3 = imread('33-0000.jpg') ;
im4 = imread('34-0000.jpg') ;
im5 = imread('35-0000.jpg') ;
im6 = imread('36-0000.jpg') ;
im7 = imread('37-0000.jpg') ;
im8 = imread('38-0000.jpg') ;
im1 = imresize(im1,[25 50]) ;
im2 = imresize(im2,[25 50]) ;
im3 = imresize(im3,[25 50]) ;
im4 = imresize(im4,[25 50]) ;
im5 = imresize(im5,[25 50]) ;
im6 = imresize(im6,[25 50]) ;
im7 = imresize(im7,[25 50]) ;
im8 = imresize(im8,[25 50]) ;
im1 = rgb2gray(im1) ;
im2 = rgb2gray(im2) ;
%%im3 = rgb2gray(im3) ;
%%im4 = rgb2gray(im4) ;
im5 = rgb2gray(im5) ;
im6 = rgb2gray(im6) ;
%%im7 = rgb2gray(im7) ;
im8 = rgb2gray(im8) ;
M(:,:,1) = im1 ;
M(:,:,2) = im2 ;
M(:,:,3) = im3 ;
M(:,:,4) = im4 ;
M(:,:,5) = im5 ;
M(:,:,6) = im6 ;
M(:,:,7) = im7 ;
M(:,:,8) = im8 ;
hf2 = figure ;
hs = slice(M,[],[],1:8) ;
shading interp
set(hs,'FaceAlpha',0.8);
here is the full code. i know i should use loops but will incoporate them after i ontain the output.
and i have attached the input images.
Jan
Jan el 28 de Mzo. de 2019
Editada: Jan el 28 de Mzo. de 2019
M = zeros(25, 50, 8);
for k = 1:8
img = imread(sprintf('%d-0000.jpg', k + 30));
img = imresize(img, [25 50]);
img = im2double(rgb2gray(img)); % Convert to double format
M(:, :, k) = img;
end
hf2 = figure ;
hs = slice(M,[],[],1:8) ;
shading interp
set(hs,'FaceAlpha',0.8);
what am i doing wrong?
also why should the images be converted to double?cap2.JPG
Pawan Kumar PS
Pawan Kumar PS el 28 de Mzo. de 2019
Editada: Pawan Kumar PS el 28 de Mzo. de 2019
i am using matlab R2013a

La pregunta está cerrada.

Etiquetas

Preguntada:

el 28 de Mzo. de 2019

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by