Effacer les filtres
Effacer les filtres

Error message 'Error using fft Invalid data type. First argument must be double, single, int8, uint8, int16, uint16, int32, uint32, or logical."

3 vues (au cours des 30 derniers jours)
I have got the following code to find third harmonic from a rheology test. There is some more code after this but I am stuck at this point because the fft function wont ren. Please could someone help me figure out how I can modify the code to evaluate the fft?
waitfor(msgbox('Select strain file, .txt')); % asks for strain file
[filename,pathname,filterindex] = uigetfile('*.txt'); % gets selected file
S = (importdata(strcat(pathname,filename))); % joins filename and path and imports data
Output = S.data(:,1:3); % sets Output to the first three columns of strain file (Strain, frequency, temperature)
Output = [Output zeros(size(Output,1),17)]; % adds 17 columns to output
Strain=(Output(:,1)/100); % calculates non dimensional strain from percentage
Output = [Output Strain]; % adds non dimensional strain to end of file
waitfor(msgbox('Select output folder')); % asks user where to put output file
outputfolder = uigetdir; % gets selected folder
count=1 %counter for each file processed, sets initially to 1
for Stress=PVDFPT3Hstress %for each text file in the folder of stress files
w= S.data(count,2); %reads frequency from column 2 in strain file
T = PVDFPT3Hstress(:,3:3); %time data from file
B = PVDFPT3Hstress(1:21,4:4); %stress data from file
Z = PVDFPT3Hstress(:,5:5); % strain data from file
DT=6.673 ;% mean difference between steps
cycletime = 1/w; % time for 1 cycles
pointspercycle = cycletime/DT; %finds points per cycle
initialsize = size(Z,1); %gets starting number of points
initialsize2 = size(Z,1); %gets starting number of points (minus 1st 5% cycles)
Fs=1/DT;
N = size(B,1);
r=round(N/2);
freq= (Fs*(0:1/r:1-1/r))/2; % 0 to r-1 give 0, 0 +1/r, 0+2/r etc.
y=B./r;
x = fft(y);
  3 commentaires
Hafsah
Hafsah le 27 Nov 2023
pvdfstress contains the time, stress and strain values from the experiment.
y is each stress value divided by an integer (r), hence, y is an array.
Please lmk if you have any other follow-up questions
Walter Roberson
Walter Roberson le 27 Nov 2023
If it contains a time... it's probably in the form of a table() object.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 27 Nov 2023
for Stress=PVDFPT3Hstress %for each text file in the folder of stress files
It is often overlooked in the documentation, but when you use a for loop, the looping is over the columns of the object on the right-hand side of the =
T = PVDFPT3Hstress(:,3:3); %time data from file
That hints that the variable on the right side of the for loop is a 2D array
Z = PVDFPT3Hstress(:,5:5); % strain data from file
with at least 5 columns.
So the first time through the for loop, the data would be copied from PVDFPT3Hstress(:,1) into Stress. The second time through the for loop, the data would be copied from PVDFPT3Hstress(:,2) into Stress . And so on.
My guess about what is happening is that I suspect that PVDFPT3Hstress is a table object, and therefore that B = PVDFPT3Hstress(1:21,4:4) is a table object with 21 rows and 1 variable.
You are using R2023b, and new in R2023b is that if you use a table object with an arithmetic operation such as in your y=B./r; line, then MATLAB will attempt to apply the arithmetic operation to each variable in the table object, producing a table object as output. So I suspect your y is a table object with one variable.
Reminder: if you have table objects, then it is recommended to access them by variable name, as in
B = PVDFTL3Bstress.stress(1:21);
and if you must use numeric subscripts, then use { } to extract the data, as in
B = PVDFPT3Hstress{1:21,4};
  5 commentaires
Walter Roberson
Walter Roberson le 27 Nov 2023
B = PVDFPT3Hstress{1:21,4}; %notice the { and } rather than ( and )
N = size(B,1);
r=round(N/2);
freq= (Fs*(0:1/r:1-1/r))/2; % 0 to r-1 give 0, 0 +1/r, 0+2/r etc.
y=B./r;
x = fft(y);
Walter Roberson
Walter Roberson le 27 Nov 2023
Please show
fprintf('Variable names\n');
PVDFPT3Hstress.Properties.VariableNames(:)
fprintf('Variable Classes\n');
classes = varfun(@(V)string(class(V)), PVDFPT3Hstress);
classes{:,}(:)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Stress and Strain dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by