Cell Struct and Tables

1 view (last 30 days)
BoostedMan
BoostedMan on 18 Dec 2020
Answered: Walter Roberson on 20 Dec 2020
So im tring to make this "Car Chooser" program, that when you answer all the questions it uses the intersect funtion to tell you, out of all the answered questions, which cars are for you. But whenever I try it, it works for the first 2 questions, and then disregards the other questions. For example I answered questions to get an audi a4, but when it gives me my final table, the audi a4 isnt there, but there are otehr cars that dont fir the parameters I chose. Looking through it its sond but im not sure why this is happening.
(I put the car catalog in ther etoo but thats the same as carcat, just for easier viewing fi it helps)
Basically the code doesnt work how intended and I cant figure out why.

Answers (1)

Walter Roberson
Walter Roberson on 20 Dec 2020
if a == 1
ip1 = [Car.type] == 1;
elseif a == 2
ip1 = [Car.type] == 2;
elseif a == 3
ip1 = [Car.type] == 3;
end
That could be coded more simply as
ip1 = [Car.type] == a;
Then
if d == 1
ip4 = [Car.seats] == 2;
elseif d == 2
ip4 = [Car.seats] >= 5;
elseif d == 3
ip4 = [Car.seats] >= 7;
end
What about the very common 4 seat car? Your logic about 5 and 7 is that you look for cars with at least 5 or at least 7, but you do not do the same thing for 2.
Q5 = 'Is speed/performance important to you?';
A5 = '1. Yes 2. No: ';
disp(Q5)
e = input (A5);
if e == 1
ip5 = [Car.sport] == 1;
elseif e == 2
ip5 = [Car.sport] == 1 & [Car.sport] == 2;
end
There are no possible values of Car.sport that can simulteneously == 1 and == 2 . This is a real bug in your program. You should be using | instead of & there.
if f == 1
ip6 = [Car.size] == 1;
elseif f == 2
ip6 = [Car.size] == 2;
elseif f == 3
ip6 = [Car.size] == 3;
elseif f == 4
ip6 = [Car.size] == 4;
end
That could be coded more simply as
ip6 = [Car.Size] == f;

Community Treasure Hunt

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

Start Hunting!