Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
how to alter this code because its give me error/
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Image Analyst
am 2 Mai 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
am 2 Mai 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.
Antworten (0)
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!