Exceeds the number of array elements (0).
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi everyone,
I have got the error in the code below, What should I do to fix it?
Code
% convert finite values to indices between 1 and map length
n = size(map, 1);
inds = (img(valid)-bounds(1))/(bounds(end)-bounds(1))*(n-1);
inds = floor(min(max(inds, 0), n-1))+1;
Error
Index exceeds the number of array elements (0).
Error in double2rgb (line 44)
ins = (img(valid)-bounds(1))/(bounds(end)-bounds(1))*(n-1);
채택된 답변
Voss
2023년 1월 24일
0 개 추천
Either img or bounds (or both) is empty.
Check img and bounds and figure out why one or both is not what you expect.
댓글 수: 9
Neda Deljavan
2023년 1월 25일
편집: Stephen23
2023년 1월 26일
"img" and "bounds" are in the function "double2rgb.m" that I used in my code.
COPYRIGHT code removed. Please do not post copyright code on this forum. Original source:
I got the error in using the above function in my code below:
Code:
%Rescaling network features for plotting networks
grafo = graph(W); % converting matrix to graph list of edges
links = table2array(grafo.Edges); % converting the graph object into a table
wij = links(:,3); % taking only link weigths
a = 1; b = 10; % range for rescaling limits
wij = ( (wij - min(wij)).*(b-a) )/(max(wij) - min(wij)); % rescaling formula
wij = wij+0.5;
rgb = squeeze(double2rgb(wij, colormap(jet))); close % mapping values to RGB colors with pallete JET
a = 1; b = 10; % range for rescaling limits
wij = ( (wij - min(wij)).*(b-a) )/(max(wij) - min(wij)); % rescaling formula
wij = wij+0.5;
So, I could not deal with the error. Please help me.
Thanks in advance.
Voss
2023년 1월 26일
Like I said, if img is empty, then you'll get the error you got.
Maybe wij is empty because links has zero rows. I don't know because I don't have your data. You'll have to check on that.
Yes, you are right. wij is NaN. What should I do?
I will display codes before wij step by step below:
grafo = graph(W);



links = table2array(grafo.Edges);

wij = links(:,3);

a = 1; b = 10; % range for rescaling limits
wij = ( (wij - min(wij)).*(b-a) )/(max(wij) - min(wij)); % rescaling formula
wij = wij+0.5;

So, due to this NaN, rgb does not run:
rgb = squeeze(double2rgb(wij, colormap(jet)));
What should I do? Thanks in advance for your help.
Do not use double2rgb(). Use
rgb = ind2rgb(uint8(rescale(wij, 0, 255)), jet);
Yesss. It solved :) Thanksss a billion.
Also, I add 0.01 in the denominator of wij and it works:
wij = ( (wij - min(wij)).*(b-a) )/((max(wij) - min(wij))+0.01);
Due to wij is NaN.
I fixed the problem of wij, but I got the error in the next step which is:
Code:
%% step24: Plotting a Functional Network
figure
hold on;
% ind=find(isnan(wij));
% wij(ind)=0.01;
for ll = 1 : length(links) %% plotting links
line([EEG.chanlocs(links(ll,1)).X, EEG.chanlocs(links(ll,2)).X], [EEG.chanlocs(links(ll,1)).Y, EEG.chanlocs(links(ll,2)).Y], 'LineWidth', wij(ll), 'Color', rgb(ll,:) );
end
colormap(jet);
% colorbar
for nn = 1 : 4 %% plotting nodes
plot(EEG.chanlocs(nn).X, EEG.chanlocs(nn).Y, 'ro', 'MarkerSize', st(nn), 'MarkerFaceColor', 'y')
text(EEG.chanlocs(nn).X+0.5, EEG.chanlocs(nn).Y, EEG.chanlocs(nn).labels, 'FontSize', 11);
end
view([270 90]); %% rotating to vertical view
axis equal; axis off;
set(gcf, 'units','normalized','outerposition',[0 0 1 1]) %EXPANDING FIGURE ON SCREEN
Error:
Index in position 1 exceeds array bounds (must not exceed 1).
Error in NEW1 (line 452)
line([EEG.chanlocs(links(ll,1)).X, EEG.chanlocs(links(ll,2)).X], [EEG.chanlocs(links(ll,1)).Y, EEG.chanlocs(links(ll,2)).Y], 'LineWidth', wij(ll),
'Color', rgb(ll,:) );
We do not have your current code, and we do not have your data to test with.
As outside observers, we have no reason to expect that EEG.chanlocs is not (for example) a transfer function that does not have an X field at all. Or maybe EEG is a graph() object that you added a chanlocs property to. We have no way of knowing.
After the section above, for running code below I've got an error, what's the problem?
Code:
for ll = 1 : length(links) %% plotting links
line([EEG.chanlocs(links(ll,1)).X, EEG.chanlocs(links(ll,2)).X], [EEG.chanlocs(links(ll,1)).Y, EEG.chanlocs(links(ll,2)).Y], 'LineWidth', wij(ll), 'Color', rgb(ll,:) );
end
colormap(jet);
% colorbar
for nn = 1 : 4 %% plotting nodes
plot(EEG.chanlocs(nn).X, EEG.chanlocs(nn).Y, 'ro', 'MarkerSize', st(nn), 'MarkerFaceColor', 'y')
text(EEG.chanlocs(nn).X+0.5, EEG.chanlocs(nn).Y, EEG.chanlocs(nn).labels, 'FontSize', 11);
end
view([270 90]); %% rotating to vertical view
axis equal; axis off;
set(gcf, 'units','normalized','outerposition',[0 0 1 1]) %EXPANDING FIGURE ON SCREEN
Error:
Error using line
Value should be a finite number greater than 0
Error in NEW1 (line 452)
line([EEG.chanlocs(links(ll,1)).X, EEG.chanlocs(links(ll,2)).X], [EEG.chanlocs(links(ll,1)).Y, EEG.chanlocs(links(ll,2)).Y], 'LineWidth', wij(ll),
'Color', rgb(ll,:) );
Thanks in advance for your help.
Bests,
Neda
My guess is that wij(ll) is NaN or Inf or a non-positive number.
You can see below that those cases throw the error you got:
try
line([1 2],[1 2],'LineWidth',NaN)
catch e
delete(gca())
disp(e.message);
end
Value should be a finite number greater than 0
try
line([1 2],[1 2],'LineWidth',Inf)
catch e
delete(gca())
disp(e.message);
end
Value should be a finite number greater than 0
try
line([1 2],[1 2],'LineWidth',0)
catch e
delete(gca())
disp(e.message);
end
Value should be a finite number greater than 0
try
line([1 2],[1 2],'LineWidth',-1)
catch e
delete(gca())
disp(e.message);
end
Value should be a finite number greater than 0
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Antennas, Microphones, and Sonar Transducers에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
