Index exceeds the number of array elements (1).

Hello ,
Can someone tell me where am I wrong here? I am retrieving only 1024 values from 3072 after comparing each row from 3 same columns.
w = zeros(1, 1024);;%1024 length
l=length(h_im);
x=4;
y=2;
for k = 1 : numel(h_im)
a =zeros(1, 4096);
end
for i = 1 : numel(d)
dl = zeros(1, numel(W)); length %1024
for h =1:3
if a(i*3+h)>0 %%%% error is here
dl = dl+1;
else
dl = dl-1;
end
end
end

3 comentarios

Ive J
Ive J el 18 de Feb. de 2021
Editada: Ive J el 18 de Feb. de 2021
You already answered yourself I guess: 3072 > 1024. Your first loop counter cannot go above numel(w_im).
Btw, your first loop doesn't do anything, you loose a after each loop execution.
marie lasz
marie lasz el 18 de Feb. de 2021
Yes I know but I need only 1024 values , i have 3 columns anfd 1024 rows = 3072 values now i want to compare each row and extract one value .
marie lasz
marie lasz el 18 de Feb. de 2021
even by making length equal in each loop still gives this error

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 18 de Feb. de 2021
for k = 1 : numel(h_im) % the length is 3072
a(k) = w_im{k}(x,y) - h_im{k}(x,y);
end
and
if dl > 0
w(i) = 1;
else
w(i) = 0;
end
simplifies to
w(i) = double(dl > 0); % Double is not necessary if you're happy with w as a logical.

5 comentarios

marie lasz
marie lasz el 18 de Feb. de 2021
actually from 3072 values i have to extract 1024 values by comparing each row's values. If I apply this simplified code it wiull give me 3072 values.
Hard to say until you supply us with the variables you are starting with in a .mat file with the paper clip icon.
save('answers.mat', 'w_im', 'h_im', 'W');
marie lasz
marie lasz el 19 de Feb. de 2021
w_im=1x3072 cell
h_im=1x3072 cell
W=32x32 logical
marie lasz
marie lasz el 19 de Feb. de 2021
I solved the problem. thank you for your time :-)
Rik
Rik el 19 de Feb. de 2021
Next time, please try to post a minimal working example. That means you post as much code as is needed to result in the unwanted behavior, but not more.
You should also do yourself a favor: write comments. I tend to suggest that half of your m file should be green. That is probably too much, but if you really try to explain the purpose of every line, you will make it a lot easier for others to read your code. In two weeks you will be unable to understand what you did here.

Iniciar sesión para comentar.

Categorías

Preguntada:

el 18 de Feb. de 2021

Editada:

el 20 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by