Want to plot the vector field with streakarrow function but get the error
1 回表示 (過去 30 日間)
古いコメントを表示
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
% 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??
0 件のコメント
回答 (1 件)
Siraj
2023 年 11 月 1 日
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 file “flowField.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);
It is recommended to check for duplicates in the data used to generate the coordinates and try again. Hope this helps.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Contour Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!