Header text in an Excel spreadsheet has been imported into MATLAB as a single-ro
ID: 3883383 • Letter: H
Question
Header text in an Excel spreadsheet has been imported into MATLAB as a single-row cell array named Headers. The contents of Headers is {'Temp (T) [degree C]' 'Volume (V) [cc]' 'Amount (n) [mol]'} You are going to process numerical data also imported from the spreadsheet (in a matrix), doing some unit conversions and creating some new data columns. You wish to modify the cell array Headers to reflect these changes and additions. Show the code you would use to modify the individual elements as well as add two new elements to Headers so that its new contents is {'Temp (T) [K]' 'Volume (V) [m^3]' 'Amount (n) [mol]' 'Pressure (P) [atm]' 'Status'} Show individual commands to modify each separate element: do not simply redefine Headers with a single statement.Explanation / Answer
MATLAB Code:
clc;
close all;
clear;
%% Program strats here
strings = {'Temp (T) [C]','Volume (V) [cc]','Amount (n) [mol]'}
%% Modify first element
disp ('After modification')
strings{1,1}='Temp (T) [K]';
%% Modify second element
strings{1,2}='Volume (V) [m^3]';
%% Adding two new elements
strings{1,4}='Pressure (P) [atm]';
strings{1,5}='Status'
OUTPUT:
strings =
'Temp (T) [C]' 'Volume (V) [cc]' 'Amount (n) [mol]'
After modification
strings =
Columns 1 through 4
'Temp (T) [K]' 'Volume (V) [m^3]' 'Amount (n) [mol]' 'Pressure (P) [atm]'
Column 5
'Status'