indexing must appear last in an index espression

조회 수: 1 (최근 30일)
Bhargavkrishna Kondreddy
Bhargavkrishna Kondreddy 2016년 10월 24일
편집: Jan 2016년 10월 26일
Xsum =A(1)(:,3); error is at this point for k = 2:299 Xsum=Xsum+A(k)(:,3); end

채택된 답변

Jan
Jan 2016년 10월 25일
편집: Jan 2016년 10월 26일
A(k) is the k.th element of the array A. Then indexing another time by "(:,3)" is not valid Matlab syntax. We cannot guess the purpose of this code, so please explain the class and dimensions of A and what you want to achieve.
[EDITED, after you provided the code]
I guess that:
Xsum = A(1)(:,3)
should be
Xsum =A{1}(:,3)
and the same for "Xsum=Xsum+A(k)(:,3)".
Compare it with the lines:
Ysum = A{1}(:,4); for m = 2:299 Ysum=Ysum+A{m}(:,4); end

추가 답변 (1개)

Bhargavkrishna Kondreddy
Bhargavkrishna Kondreddy 2016년 10월 25일
this code is meant for importing 300 .txt files and summing and mean of all values of the files and plotting the final results. clear all clc;
% Generating 2D Meshgrid [X,Y] = meshgrid(185:8:849,169:8:625); %-------------------------------
% Importing all the 300 files
files = dir( 'imageset1_*.txt'); for i=1:numel(files) A{i} = dlmread( files(i).piv, '\t', 3 , 0 ); end
% Summation of X-components of the 300 files
Xsum =A(1)(:,3); for k = 2:299 Xsum=Xsum+A(k)(:,3); end
% Taking average of the X-components of the 300 files
Xavg = Xsum/299; %Xavg(isnan(Xavg)) = 0;
% Summation of Y-components of the 300 files
Ysum = A{1}(:,4); for m = 2:299 Ysum=Ysum+A{m}(:,4); end
%Taking average of the Y-components of the 300 files
Yavg = Ysum/299; %Yavg(isnan(Yavg)) = 0;
% Calculating the magnitude of the X-component and Y-component
Zavg = sqrt(Xavg.^2+Yavg.^2);
% Making the NaN Values Zero
Zavg(isnan(Zavg)) = 0;
% Creating a Dummy Matrix of 12 x 18
Zplot = rand(58,84); %--------------------------------------------------
% Assigning the Value of Zavg in the Dummy Matrix
for e = 1:4872 %------------------------------------------------------- Zplot(e)=Zavg(e); end
%*********************************************************************** % Creating a Dummy Matrix of 12 x 18
Xplot = rand(58,84); %--------------------------------------------------
% Assigning the Value of Zavg in the Dummy Matrix
for e = 1:4872 %------------------------------------------------------- Xplot(e)=Xavg(e); end
% Creating a Dummy Matrix of 12 x 18
Yplot = rand(58,84); %--------------------------------------------------
% Assigning the Value of Zavg in the Dummy Matrix
for e = 1:4872 %------------------------------------------------------- Yplot(e)=Yavg(e); end
%***********************************************************************
%Contour Plot figure; contour(X,Y,Zplot,100,'LineWidth',3,'Fill','on','clipping','off'); xlabel('\fontsize{20}X - Pixels'); ylabel('\fontsize{20}Y - Pixels'); title('\fontsize{22}CONTOUR PLOT'); colorbar; hold on; quiver(A{1}(:,1),A{1}(:,2),Xavg,Yavg,'color','black'); axis([200 800 100 700]);%%%%%%%%%%%%%% colormap('jet');
% Setting the minimum and the maximum limit of the colormap and colorbar on the contour plot caxis([0 10]);
% Overlapping the overlapped images with the velocity vectors
figure; load('matlab.mat'); imcropped_93=imcrop(imcell1_93,[195 182 631 434]); imshow(imcropped_93); hold on; quiver(A{1}(:,1)-195,A{1}(:,2)-182,Xavg,Yavg,'color','yellow');
hold on;
  댓글 수: 1
Jan
Jan 2016년 10월 26일
Please format your code using the "{} Code" button. Currently it is not readable.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by