Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

how to alter this code because its give me error/

1 visualización (últimos 30 días)
Firas Al-Kharabsheh
Firas Al-Kharabsheh el 2 de Mayo de 2016
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
M =[ 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 1 1 1 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1 0 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 0 0 0 0
0 0 0 1 1 1 1 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 1 1 1 1 1 1 0 0
0 1 1 1 1 1 1 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 0 1 0 1 1 1 1 1 1
0 1 1 1 1 0 0 1 0 0 1 1 1 1 0
0 0 0 0 0 0 1 1 1 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 ];
[n,m]=size(M);
b=cell(n,1);
c=cell(1,m);
maxb=ceil(m/2);
maxc=ceil(n/2);
for k=1:n
a=[0 M(k,:) 0];
ii1=strfind(a,[0 1]);
ii2=strfind(a,[1 0]);
maxb=max(maxb,numel(ii1));
b{k}=ii2-ii1;
end
for k=1:m
a=[0 M(:,k)' 0];
ii1=strfind(a,[0 1]);
ii2=strfind(a,[1 0]);
maxc=max(maxc,numel(ii1));
c{k}=(ii2-ii1)';
end
M_row=cell2mat(cellfun(@(x) [x zeros(1,maxb-numel(x))],b,'un',0));
M_column=cell2mat(cellfun(@(x)[zeros(maxc-numel(x),1);x],c,'un',0));
M_C = (M_column)';
F=zeros(n,m); % preallocate output
ix=find(sum(M_row,2)+sum(M_row~=0,2)-1==m); % rows contain some ones
F(ix,:)=1; % start with all '1'
F(sub2ind(size(F),ix,M_row(ix,1)+1))=0 ;
  • give me error in F(sub2ind(size(F),ix,M_row(ix,1)+1))=0 ;
(Error using sub2ind Out of range subscript.)
  4 comentarios
Image Analyst
Image Analyst el 2 de Mayo de 2016
Tell us what you want to do to that matrix. It seems unnecessarily complicated. I don't think you should have to converting to cell arrays and messing with cellfun() and cell2mat(), etc. It might be able to be done much simpler just as simple numerical matrices or images. Maybe even one line of code if you want a typical image processing type of operation. Just describe in words what you want to do. At least throw in some comments - the most glaring sign of bad code is no comments. But an overall description would be better than comments step-by-step in code that is taking a bad approach.
Stephen23
Stephen23 el 2 de Mayo de 2016
@Image Anaalyst: there have been ten or twenty questions (I didn't keep count) on this matrix, and similar variations. The requirements change each day, and so do the answers...
Task solving by iterative online-forum code generation.
@Firas Al-Kharabsheh: It would be useful to actually get a real explanation of what the goal is, and then perhaps we could suggest a robust way to approach the task.

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by