## How can I use each element from an Array to substract other elements from other arrays and create new matrix?

### Ikke dettenei (view profile)

on 15 May 2018
Latest activity Commented on by Jan

on 20 May 2018

### Guillaume (view profile)

Hi there! I am new to Matlab.
I have create a structArray with Different EV`s and I want to compare them both using distances I have on other matrixes
Here you see the structArray I have created of my EV`s:
EV(1).name = 'Nissan Leaf 24 kWh pack'
EV(1).RangeInKM= 199
EV(2).name = 'Nissan Leaf 30 kWh pack'
EV(2).RangeInKM = 250
And here I have 2 arrays with distance to a Specific place from random starting places.
KM_to_Durres = [13.7; 13.3; 12.7; 11.3; 7.4; 6.1; 8.7; 14.4; 16.4; 21.2; 23.4; 21.3; 18.5; 17.1; 22.2;]
KM_to_Fier= [8.7; 8.7; 8.1; 9.3; 13.9; 17.5; 9.7; 8.4; 4.8; 4.1; 6.7; 1; 7.9; 10.2; 18.2; ]
How can I Iterate through these 2 arrays and subtract the numbers from EV(1).RangeInKM and EV(2).RangeInKM and then create a new array with the result?
Thank you.

### Guillaume (view profile)

on 15 May 2018
Edited by Guillaume

### Guillaume (view profile)

on 15 May 2018

distances = [KM_to_Durres, KM_to_Fier];
remainingrange = arrayfun(@(s) s.RangeInKM - distances, EV, 'UniformOutput', false)
This returns a cell array where each cell corresponds to the correspond EV element.
Or you can use an explicit loop:
remainingrange = cell(size(EV));
for evidx = 1:numel(EV)
remaingrange{evidx} = EV(evidx).RangeInKM - distances;
end
Both achieve the same result.

Ikke dettenei

### Ikke dettenei (view profile)

on 20 May 2018

Okay boss, So now I have added a couple of EV`s into my EV matrix containing some information about each EV by manufacturer, I also added multiple districts to my districts array(For personal reason I dont want to include all names).

• Question 1: Is it possible to create with random picking of some of these destination, and then show a "remaining_range" table of all EV?
• Question 2: Is it also possible to create a matrix with battery-status (SOC-table) for all EV after a random destination? e,g:(remaining_range/RangeInKM_By_Manufacturer * 100) gives you the current battery status after reaching a destination.
• Question 3: Is it possibble to group some of the districts into a new array/matrix? e,g dist17, dist18, dist19 are district with hotspots/tourist attractions.

My EV matrix as per now:

EVs = {'Nissan Leaf 24 kWh pack', 'Nissan Leaf 30 kWh pack', 'Volkswagen e-Golf','Tesla Model S 90(D)','BMW i3 22kWh','BMW i3 33 kWh','KIA SOUL','Volkswagen e-Up(2016)','Renault ZOE R90 Z.E 40','Hyundai IONIQ','Mercedes-Benz B250E','Tesla model X 90D'};
RangeInKM_By_Manufacturer = [199 250 300 557 190 300 250 160 403 280 200 489];
RangeInKM_Winter =[100 125 200 453 80  125 150 120 311 160 120 435];
RangeInKM_Summer =[150 200 300 525 160 200 220 165 403 240 200 489];
Battery_Capacity =          [21.6 27.2 31.5 82 18.8 27.2 30 16.8 41 28 32 0]
Battery_Warranty_KM =  [100000 160000 160000 160000 100000 100000 150000 160000 160000 200000 100000 999999]
Battery_Warrany_Year = [5 8 8 8 8 8 7 8 8 8 8 8 ]
EnginePower_Kw = [80 80 100 310 125 125 81 60 68 88 180 311]
EnginePower_hK = [109 109 136 422 170 170 110 82 92 120 340 411]
Torque_in_NewtonMeter = [254 254 290 660 250 250 250 210 225 295 295 600]
QuickChargingEffect_kW_DC = [50 50 40 135 50 50 100 40 0 70 0 132 ]
NormalCharging_OnBoard_kW_AC = [3.3 6.6 7.2 11 3.7 7.4 6.6 3.3 22 6.6 11 11];
TopSpeed_KM_per_hour = [144 144 150 250 150 150 145 130 135 165 160 250]
Acceleration_0to100KM_per_hour = [11.5 11.5 9.6 4.4 7.3 7.3 11.2 12.4 13.2 9.9 7.9 3.9]
RangeInKM_By_Manufacturer_RANK = [10 8 4 1 11 5 7 12 3 6 9 2]
Ikke dettenei

### Ikke dettenei (view profile)

on 20 May 2018
My district matrix: I have problems putting all my distances here, so I put a picture instead of code:
Jan

### Jan (view profile)

on 20 May 2018
[MOVED from flags] Vlorjan Badallaj wrote:
Trying to improve slowly and slowly