MATLAB Answers

0

indexing must appear last in an index espression

Latest activity Edited by Jan
on 26 Oct 2016
Accepted Answer by Jan
Xsum =A(1)(:,3); error is at this point for k = 2:299 Xsum=Xsum+A(k)(:,3); end

  0 Comments

Sign in to comment.

Tags

No tags entered yet.

2 Answers

Answer by Jan
on 25 Oct 2016
Edited by Jan
on 26 Oct 2016
 Accepted Answer

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

  0 Comments

Sign in to comment.



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 Comment

Jan
on 26 Oct 2016
Please format your code using the "{} Code" button. Currently it is not readable.

Sign in to comment.