Error using cat: Dimensions of matrices being concatenated are not consistent.
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello!
I have this program that, at the end, I need to assemble a matrix with 5 columns: var1, var2, var3, var4 and hh. However I get this error: Error using cat Dimensions of matrices being concatenated are not consistent.
clear all;
close all;
str='/home/pink/Documents';
folder_name = uigetdir(str);
files = dir(fullfile(folder_name,'*.dat'));
curr_folder=pwd;
cd(folder_name);
for i = 1:length(files);
fileID = fopen(files(i).name);
ref = fread(fileID,[500 500], 'float32');
teste = find(ref<0);
ref(teste) = NaN;
rot = rot90(ref);
latitude = [-3.63965:-0.00898:-8.12601];
longitude = [-37.5098:0.00906:-32.9831];
L1 = 1;
L2 = 500;
for LL = L1:L2;
array_latitude (1:500,LL) = latitude;
end
array_lat = array_latitude(1:500,1:500);
array_lat;
for Lll = L1:L2;
array_longitude(Lll,1:500) = longitude;
end
array_long = array_longitude(1:500,1:500);
array_long;
var1 = find(rot>=20);
var2 = array_lat(var1);
var3 = array_long(var1);
var4 = rot(var1);
for j = 1:length(var1);
name = files(i).name;
s = strsplit(name,'_');
km = s{3};
alt{j,1} = km;
end
hh = cellfun(@str2double,alt);
B = cat(2,var1,var2,var3,var4,hh);
end
The problem is in this loop. For each file that opens, I have a different size for var1 and, consequently, the size of hh should change and is not changing, so it says that the dimensions are different.
for j = 1:length(var1);
name = files(i).name;
s = strsplit(name,'_');
km = s{3};
alt{j,1} = km;
end
hh = cellfun(@str2double,alt);
I would like help to solve this problem.
댓글 수: 0
답변 (1개)
dpb
2020년 9월 3일
latitude = [-3.63965:-0.00898:-8.12601];
longitude = [-37.5098:0.00906:-32.9831];
str='/home/pink/Documents';
folder_name = uigetdir(str);
files = dir(fullfile(folder_name,'*.dat'));
curr_folder=pwd;
cd(folder_name);
for i = 1:length(files);
fileID = fopen(files(i).name);
ref = fread(fileID,[500 500], 'float32');
ref((ref<0)=NaN;
rot = rot90(ref);
array_lat=repmat(latitude(500,1);
array_long=repmat(longitude,500,1);
ix20 = find(rot>=20);
lat20 = array_lat(ix20);
long20 = array_long(ix20);
rot20 = rot(ix20);
hh=zeros(ix20,1);
for j = 1:length(ix20);
name = files(i).name;
s = strsplit(name,'_');
hh(j)=str2double(s{3});
end
B=cat(2,ix20,lat20,long20,rot20,hh);
end
댓글 수: 2
Walter Roberson
2020년 9월 4일
Right, the code should not be rotating the indices returned by find() and should not be treating the indices as a length. But that logic was copied from the original logic, so you will need to be the one to debug it.
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!