6 views (last 30 days)

I have a number of data files where every data file is stored in a cell array. Thus, :

datac.1 is stored in expData{1,1} at time = 1 second

datac.2 is stored in expData{2,1} at time = 2 seconds

datac.3 is stored in expData{3,1} at time = 3 seconds

... etc.

Each data file contains the (x,y,z) coordinates of each particle at a different time step.

I have also a number of data files that contain the (x,y,z) velocities of each particle at a different time step. These are also stored in a cell array. Thus,:

datav.1 is stored in velData{1,1} at time = 1 second

datav.2 is stored in velData{2,1} at time = 2 seconds

datav.3 is stored in velData{3,1} at time = 3 seconds

I succesfully managed to make a pcolor plot for one data file, as shown below.

% Width of the grid bin,m

w = 0.6;

% Length of the grid bin, m

l = 0.06;

% Height of the grid bin, m

h = 2.3;

% Bins in x-direction

nx = 1000;

% Bins in y-direction

ny = 1;

% Bins in z-direction

nz = 1000;

% Total number of bins

q = nx*ny*nz;

% Volume of a single bin

v = (w/nx)*(l/ny)*(h/nz);

xbin = (w/nx);

ybin = (l/ny);

zbin = (h/nz);

x = (1:nx)*xbin;

y = (1:ny)*ybin;

z = (1:nz)*zbin;

[X, Z] = meshgrid(x,z);

% x-coordinate of particles

xc = expData{1800,1}(:,1);

% z-coordinate of particles

zc = expData{1800,1}(:,3);

% Velocity in x-direction

vx = velData{1,1800}(:,1);

% Velocity in z-direction

vy = velData{1,1800}(:,3);

% Root sum of squares velocity

V = hypot(vx,vy);

Vtot = griddata(xc,zc,V,X,Z);

figure(2)

pcolor(X,Z,Vtot)

shading interp

I want to the the same procedure as above for all my data files. Thus, I need to loop over all the cells. I tried the following:

for m = 1:length(files)

xc{m} = expData{m,1}(:,1);

zc{m} = expData{m,1}(:,3);

vx{m} = velData{1,m}(:,1);

vz{m} = velData{1,m}(:,3);

v{m} = hypot(vx{1,m}(:),vz{1,m}(:));

V = griddata(xc,zc,v,X,Z);

figure(2)

pcolor(X,Z,V)

shading interp

end

However, I get an error that brace indexing is not supported by the function hypot.

1) How can I loop over all the files and get the pcolor for every file?

2) How can I display the colorbar of the velocity?

Steven Lord
on 10 Sep 2020

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

Start Hunting!
## 2 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/591694-error-using-brace-indexing-with-function-hypot#comment_1004065

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/591694-error-using-brace-indexing-with-function-hypot#comment_1004065

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/591694-error-using-brace-indexing-with-function-hypot#comment_1004107

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/591694-error-using-brace-indexing-with-function-hypot#comment_1004107

Sign in to comment.