I want to convert a single column of data from a .txt file as shown then operate on it by the script shown but I get error "left is 1x1 right is 1x243003"

2 Ansichten (letzte 30 Tage)
here is the .txt file except it has no space rows (this editor put those spaces geeze)
I want to keep the right I.E. 0.047817 but throw away the left column 0.666700 scroll down for rest of questiuon
0.666700 0.047817
0.676700 0.047628
0.686700 0.047439
0.696700 0.045927
0.706700 0.044415
0.716700 0.045171
0.726700 0.046116
0.736700 0.045549
0.746700 0.045171
0.756700 0.044226
0.766700 0.043470
0.776700 0.045738
0.786700 0.047439
0.796700 0.047817
0.806700 0.048762
0.816700 0.048762
0.826700 0.047628
0.836700 0.044604
0.846700 0.043659
0.856700 0.044982
0.866700 0.044226
0.876700 0.043281
0.886700 0.043848
0.896700 0.045171
0.906700 0.045738
0.916700 0.046305
0.926700 0.047250
0.936700 0.047061
0.946700 0.044415
0.956700 0.041769
here is my script which is functional in another instance where the file is retrieved by using ----- fileID=fopen('filename.txt', 'r'); this is because the 'filename.txt' file already has the left column removed.
I was trying to use import data on the above .txt file then remove the first column with data(:,2) then push into omega for the script go to bottom to see the error I get when run
Fs = 100;
t0 = 1/Fs;
data = importdata('1st stab prime1.txt');
data(:,2)
omega = data;
%disp(omega)
%omega = fscanf(fileID,formatSpec) % determine omega
%fclose(fileID);
theta = cumsum(omega, 1)*t0; %determine theta
%disp(omega);
%disp(theta);
maxNumM = 100;
L = size(theta, 1);
maxM = 2.^floor(log2(L/2));
m = logspace(log10(1), log10(maxM), maxNumM).';
m = ceil(m); % m must be an integer.
m = unique(m); % Remove duplicates.
disp(m);
tau = m*t0;
avar = zeros(numel(m), 1);
for i = 1:numel(m)
mi = m(i);
avar(i,:) = sum( ...
(theta(1+2*mi:L) - 2*theta(1+mi:L-mi) + theta(1:L-2*mi)).^2, 1);
end
avar = avar ./ (2*tau.^2 .* (L - 2*m));
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-243003.
Error in Allan_Dev_ACC_GS520_6_7_2021 (line 50)
avar(i,:) = sum( ...

Akzeptierte Antwort

Kevin Holly
Kevin Holly am 7 Jun. 2022
I imported the data with the function attached and did not recieve an error.
Fs = 100;
t0 = 1/Fs;
omega = importdata('testing.txt');
%omega = fscanf(fileID,formatSpec) % determine omega
%fclose(fileID);
theta = cumsum(omega, 1)*t0; %determine theta
disp(omega);
0.0478 0.0476 0.0474 0.0459 0.0444 0.0452 0.0461 0.0455 0.0452 0.0442 0.0435 0.0457 0.0474 0.0478 0.0488 0.0488 0.0476 0.0446 0.0437 0.0450 0.0442 0.0433 0.0438 0.0452 0.0457 0.0463 0.0473 0.0471 0.0444 0.0418
disp(theta);
0.0005 0.0010 0.0014 0.0019 0.0023 0.0028 0.0032 0.0037 0.0042 0.0046 0.0050 0.0055 0.0060 0.0064 0.0069 0.0074 0.0079 0.0083 0.0088 0.0092 0.0097 0.0101 0.0105 0.0110 0.0114 0.0119 0.0124 0.0129 0.0133 0.0137
maxNumM = 100;
L = size(theta, 1);
maxM = 2.^floor(log2(L/2));
m = logspace(log10(1), log10(maxM), maxNumM).';
m = ceil(m); % m must be an integer.
m = unique(m); % Remove duplicates.
disp(m);
1 2 3 4 5 6 7 8
tau = m*t0;
avar = zeros(numel(m), 1);
for i = 1:numel(m)
mi = m(i);
avar(i,:) = sum( ...
(theta(1+2*mi:L) - 2*theta(1+mi:L-mi) + theta(1:L-2*mi)).^2, 1);
end
avar = avar ./ (2*tau.^2 .* (L - 2*m))
avar = 8×1
1.0e-05 * 0.0880 0.1738 0.1888 0.2083 0.2112 0.1827 0.1370 0.1030

Weitere Antworten (0)

Kategorien

Mehr zu Numeric Types finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by