How to fixed the issue of variable data length ?

조회 수: 4 (최근 30일)
aa
aa 2020년 10월 11일
답변: Walter Roberson 2020년 10월 11일
Hi everyone,
May somone help me ...
Might be my problem is very puzzling... I have same type of data in two diffrent files with varying data length. I code works perfectly for one data set (A .. Attched here) but did not work for the second data set (B attched here) without any error ...
Code is as below:
clear all
clc
x = -130.04:0.0025:-129.96;
y = 45.91:0.0025:45.99;
n = length(x ) ;
m = length(y ) ;
[X,Y] = meshgrid(x,y ) ;
data = load('B.txt');
x = data(:,1) ; y = data(:,2) ; z = data(:,3 ) ;
% plot grid
plot(X,Y,'r',X',Y','r ')
hold on
for i = 1:m-1
for j = 1:n-1
% Get the points of each grid
P = [X(i,j) Y(i,j ) ;
X(i,j+1) Y(i,j+1 ) ;
X(i+1,j+1) Y(i+1,j+1 ) ;
X(i+1,j) Y(i+1,j )] ;
idx = inpolygon(x,y,P(:,1),P(:,2 )) ;
iwant = [ z(idx )] ;
plot(x(idx),y(idx ),'.')
drawnow
zStore{i,j} = z(idx);
end
end
axis([-130.04 -129.96 45.91 45.99])
%
N = max(cellfun(@numel,zStore));
zMat = nan(10000,256);
% for i = 1:numel(zStore)
k=1;
for i = 1:32
for j=1:32
zMat(1:numel(zStore{i,j}),k) = zStore{i,j};
k=k+1;
end
end
%xlswrite('data',zMat)

채택된 답변

Walter Roberson
Walter Roberson 2020년 10월 11일
Your x and y of the file are exchanged compared to your X and Y range.
You should probably be using
x = data(:,2) ; y = data(:,1) ; z = data(:,3 ) ;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by