Is there a way to use relational operators with tables

7 visualizzazioni (ultimi 30 giorni)
I have 2 large tables that I brought into Matlab (2231*8, for example), and I'm trying to run a function that will calculate values while a counter is less than a failure point from the main program, that crosses over fine. The problem is that I can't run the function because the tables don't accept relational function. I've already tried converting to arrays with table2array, which didn't work. I tried going to cell then to array, and using xlsread, but neither of those worked either. I'm sure the answer is easy, but I can't figure it out right now. Nothing else in the code is failing, so I'm not sure what it is. All that it needs to work is for the loop to run like it would with an array. And while this is tagged as homework, this is not a part of the main learning points of the assigment, that part was with taking inputs from the user, putting them into different equations, and creating different arrays from the table, none of which apply here. Thank you very much for your help, and the 2 files are attached at .mat files.
function [Toughness1, Toughness2] = Ryan_Toughness(failure1, failure2)
%This function takes the load and displacement at the point of catastrophe
%and calculates the bridges toughness using reimann sums
load('MinorDesign1.mat');
load('MInorDesign2.mat');
%load the 2 tables
displacement1 = MinorDesignA(failure1,9);
k=0;
while displacement1 ~= k,9
k=k+1;
displacement1 = MinorDesignA(k,9);
deltax = k;
end
%To find total number of "ks", need to wait for it to be equal, same with
%th ones below, just slight variations.
loadchange = MinorDesignA(failure1,2);
C=0;
while loadchange ~= C,2
C=C+1;
loadchange = C,2;
deltal = (C/2);
end
u = (deltax*deltal);
Toughness1 = failure1*u;
displacement2 = MinorDesignB(failure2,9);
A=0;
while displacement2 ~= A,9
A=A+1;
displacement2 = MinorDesignB{A,9};
deltaX = A;
end
loadchange = MinorDesignB(failure1,2);
B=0;
while loadchange ~= B,2
B=B+1;
loadchange = B,2;
deltaL = (B/2);
end
u2 = (deltaX*deltaL);
Toughness2 = failure2*u2;

Risposte (1)

Steven Lord
Steven Lord il 26 Feb 2019
That is correct, the relational operators are not defined for table arrays. A table array can contain a mix of numeric and non-numeric data and operations like > may not be defined and/or make sense for the non-numeric data. Is "banana" > 3? Does that question even make sense to ask?
You can perform relational operations on the variables inside a table if you want.
load patients
patients = table(LastName,Gender,Age,Height,Weight,Smoker,Systolic,Diastolic);
patientsOver40 = patients(patients.Age > 40, :)
patientsOver40LessThan66Inches = patientsOver40(patientsOver40.Height < 66, :)
There is one other point I want to ask you about.
while loadchange ~= C,2
C=C+1;
loadchange = C,2;
deltal = (C/2);
end
What do you think the expression "C,2" does on the first and third lines of this code? If you think that this while condition will be satisfied when loadchange is neither equal to C nor equal to 2, that's not what it does. You may also want to be careful if loadchange can be non-scalar. if and while behave differently than some people expect in that scenario; see the second item in the Tips section on the documentation page for while. You may need or want to use logical indexing instead.

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Tag

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by