Effacer les filtres
Effacer les filtres

indexing must appear last in an index espression

2 vues (au cours des 30 derniers jours)
Bhargavkrishna Kondreddy
Bhargavkrishna Kondreddy le 24 Oct 2016
Modifié(e) : Jan le 26 Oct 2016
Xsum =A(1)(:,3); error is at this point for k = 2:299 Xsum=Xsum+A(k)(:,3); end

Réponse acceptée

Jan
Jan le 25 Oct 2016
Modifié(e) : Jan le 26 Oct 2016
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

Plus de réponses (1)

Bhargavkrishna Kondreddy
Bhargavkrishna Kondreddy le 25 Oct 2016
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 commentaire
Jan
Jan le 26 Oct 2016
Please format your code using the "{} Code" button. Currently it is not readable.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Orange dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by