필터 지우기
필터 지우기

error using horzcat for multiple files

조회 수: 1 (최근 30일)
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2017년 12월 6일
댓글: MAHMOUD ALZIOUD 2017년 12월 6일
hello everyone, i wrote this code to read text files with extension YO7, each file represents a month in the year, when i run it for 2 cards (2 months) it works, but when i add the third card or month it gives error, any ideas what to do here please?
for K = 1 : length(directory)
filename = directory(K).name;
fileID = fopen(filename,'r');
formatSpec = '%s';
A_cell = textscan(fileID,formatSpec);
A=char(A_cell{1,1}{:,:});
A(find(isnan(A)))=0;
[rows,columns]=size(A);
if columns~=105
ArrayTemp=zeros(rows,105);
ArrayTemp(1:rows,1:columns)=A;
A=ArrayTemp;
A=char(A);
A(isspace(A)) = '0';
end
x1=filename;
xtr=strcat('C:\Users\maa285\Desktop\New folder (2)',x1);
fid = fopen( xtr, 'wt' );
StationID = A(:,4:9);
Year_of_Data = A(:,12:13);
Month_of_Data = A(:,14:15);
Vehicle_Class = A(:,20:21);
Total_Weight_of_vehicle = A(:,25:28);
Number_of_axles = A(:,29:30);
A_Axle_Weight = A(:,31:33);
A_B_Axle_spacing = A(:,34:36);
B_Axle_Weight = A(:,37:39);
B_C_Axle_spacing = A(:,40:42);
C_Axle_Weight = A(:,43:45);
C_D_Axle_spacing = A(:,46:48);
D_Axle_Weight = A(:,49:51);
D_E_Axle_spacing = A(:,52:54);
E_Axle_Weight = A(:,55:57);
%This is to convert the string to numbers so it can show the output:
fprintf(fid, '%s %s %s %s %s',StationID, Year_of_Data, Month_of_Data, Vehicle_Class, Total_Weight_of_vehicle, Number_of_axles, A_Axle_Weight, A_B_Axle_spacing, B_Axle_Weight, B_C_Axle_spacing, C_Axle_Weight, C_D_Axle_spacing, D_Axle_Weight, D_E_Axle_spacing, E_Axle_Weight);
Ans_3{K}=str2num(StationID);
Ans_6{K}=str2num(Year_of_Data);
Ans_7{K}=str2num(Month_of_Data);
Ans_10{K}=str2num(Vehicle_Class);
Ans_12{K}=str2num(Total_Weight_of_vehicle);
Ans_13{K}=str2num(Number_of_axles);
Ans_14{K}=str2num(A_Axle_Weight);
Ans_15{K}=str2num(A_B_Axle_spacing);
Ans_16{K}=str2num(B_Axle_Weight);
Ans_17{K}=str2num(B_C_Axle_spacing);
Ans_18{K}=str2num(C_Axle_Weight);
Ans_19{K}=str2num(C_D_Axle_spacing);
Ans_20{K}=str2num(D_Axle_Weight);
Ans_21{K}=str2num(D_E_Axle_spacing);
Ans_22{K}=str2num(E_Axle_Weight);
%%to return the separated vectors into one new matrix with usable data:
all{K} =[Ans_3{K},Ans_6{K},Ans_7{K},Ans_10{K},Ans_12{K},Ans_13{K},Ans_14{K},Ans_15{K},Ans_16{K},Ans_17{K},Ans_18{K},Ans_19{K},Ans_20{K},Ans_21{K},Ans_22{K}];
end
  댓글 수: 6
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2017년 12월 6일
mr walter i did it, i found out that the error is in ans_7, is not consistent with the rest of the columns. thank you
i will try the line you suggested
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2017년 12월 6일
still gives: Error using horzcat Dimensions of matrices being concatenated are not consistent.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by