Filter löschen
Filter löschen

Want to plot the vector field with streakarrow function but get the error

4 Ansichten (letzte 30 Tage)
frank su
frank su am 12 Mär. 2022
Beantwortet: Siraj am 1 Nov. 2023
I want to generate the fluid flow field like the following figure.
I got a data file call flowField.dat and every row represent a point in the domain.
col 1 represent x, col 2 represent y, col 3 represent u, col 6 represent v
I am using a function called streakline (streakarrow function) to draw the flow field.
% read data
fileID = fopen('C:\Users\laserlab04\Desktop\flowField.dat','r');
formatSpec = '%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f';
dimension = [17 Inf];
data = fscanf(fileID, formatSpec,dimension);
fclose(fileID);
% plot the flow field
u = data(3,:);
v = data(6,:);
[uu,vv] = meshgrid(u,v);
x = data(1,:);
y = data(2,:);
[xx,yy] = meshgrid(x,y);
streakarrow(xx,yy,uu,vv,1,1);
There is the error 'sample point must be unique'.
Any advice??

Antworten (1)

Siraj
Siraj am 1 Nov. 2023
Hi!
It seems that you're encountering an error message saying "Sample points must be unique" while attempting to plot a vector field using the "streakarrow" function.
Since I lack information about the fileflowField.dat”, from which the data in being read, I am assuming that “x” or “y” that is extracted from “data” has some duplicate values in them, which could be causing the error.
The code uses the "meshgrid" function to generate coordinates for the "streakarrow" function. It is important that the coordinates are unique. If there are any duplicates in the "x" or "y" values, the resulting coordinates "xx" and "yy" may have repeated points, which could potentially cause an error. To verify this, you can examine the provided code.
% Generate random data
x = linspace(0, 10, 17); % x-coordinates
y = linspace(0, 10, 17); % y-coordinates
u = rand(1, 17); % u-component of velocity
v = rand(1, 17); % v-component of velocity
% x(1) = x(2);
% y(1) = y(2);
[uu,vv] = meshgrid(u,v);
[xx,yy] = meshgrid(x,y);
streakarrow(xx,yy,uu,vv,1,1);
The code above is functioning properly and does not produce any errors. However, if duplicates are introduced in either the "x" or "y" values, or in both, it produces the same error.
% Generate random data
x = linspace(0, 10, 17); % x-coordinates
y = linspace(0, 10, 17); % y-coordinates
u = rand(1, 17); % u-component of velocity
v = rand(1, 17); % v-component of velocity
x(1) = x(2); % introducing duplicate values in x
% y(1) = y(2);
[uu,vv] = meshgrid(u,v);
[xx,yy] = meshgrid(x,y);
streakarrow(xx,yy,uu,vv,1,1);
Error using matlab.internal.math.interp1
Sample points must be unique.

Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);

Error in stream2 (line 62)
sxi=interp1(xx(:),1:szu(2),sx(k));

Error in streakarrow (line 31)
XY=stream2(X0,Y0,U,V,X0,Y0);
It is recommended to check for duplicates in the data used to generate the coordinates and try again. Hope this helps.

Kategorien

Mehr zu Contour Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by