MATLAB Answers

How should I use this python file in matlab . I need to input two csv files and output is one csv file ,using this python code attached below.

10 views (last 30 days)
aditya tiwari
aditya tiwari on 27 Apr 2020
Answered: Abhishek Kumar on 11 Dec 2020
import os
#import cantera as ct # not required, if not using cantera cti file
import numpy as np
import matplotlib.pyplot as plt
p = 101325.0 # constant pressure
#gas = ct.Solution('Ethanol_31.cti') # ethanol
#gas = ct.Solution('gri30.cti') # ethanol
filename = 'output-0.2.csv' # input data
filenamer = 'reaction-0.2.csv' # input data
data_directory = 'Zeta_0' # output dir
if not os.path.exists(data_directory):
os.makedirs(data_directory)
#=============================================================================#
# if using same/converted cti file as chemkin file
#speciesNames = gas.species_names # each species
#nsp = len(speciesNames) # number of species
#molW = gas.molecular_weights # molecular weights of each species
nsp = 53 # number of species
speciesStart = 6 # species start location in output.csv, assuming starting index=0
# first line
names = []
xIndex = -1
uIndex = -1
TIndex = -1
COIndex = -1
CO2Index = -1
H2Index = -1
H2OIndex = -1
ARIndex = -1
with open(filename) as fi:
line0 = fi.readline()
names = [x.strip() for x in line0.split(',')]
for i in range(len(names)):
if names[i] == 'z' or names[i] == 'z (m)' or names[i] == 'x' or names[i] == 'x (m)':
xIndex = i
elif names[i] == 'u' or names[i] == 'u (m/s)':
uIndex = i
elif names[i] == 'T' or names[i] == 'T (K)':
TIndex = i
elif names[i] == 'CO':
COIndex = i
continue
elif names[i] == 'CO2':
CO2Index = i
continue
elif names[i] == 'H2':
H2Index = i
continue
elif names[i] == 'O2':
O2Index = i
continue
elif names[i] == 'OH':
OHIndex = i
continue
elif names[i] == 'H2O':
H2OIndex = i
continue
elif names[i] == 'CH4':
CH4Index = i
continue
elif names[i] == 'N2':
N2Index = i
continue
elif names[i] == 'AR':
ARIndex = i
continue
fig = plt.figure()
ax1 = plt.subplot(221)
ax2 = plt.subplot(222)
ax3 = plt.subplot(223)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by