How to change data into an excel file?

1 view (last 30 days)
Ryan Scott
Ryan Scott on 9 May 2020
Answered: Payas Bahade on 11 May 2020
clear;
clc;
X = readtable('FinalProj_TVdata.csv');
Y = readtable('FinalProj_Pdata.csv');
%Convert from Fahrenheit to Kelvin
TempK = ((X{:,1}-32)*5/9)+273.15;
%Determine Volume
V = X{:,2}*0.028;
I want to find out if V gets below 0.29 and if it does then I want to create a new data set with only the numbers before the volume gets to 0.29 and export that to excel. Please help!
  1 Comment
Rik
Rik on 9 May 2020
Have you done a Matlab tutorial? That should teach you how to do this.

Sign in to comment.

Answers (1)

Payas Bahade
Payas Bahade on 11 May 2020
Hi Ryan,
Logical indexing can be used to extract the required data from the given array. I have created a sample code which extracts the rows from array ‘X’ whose volume is less than 0.29 and saves this data into 'V' which gets further written into excel file ‘dataset.xlsx’. Below is the sample code:
X=[273 0.23; 274 0.24; 275 0.25; 276 0.26; 277 0.27; 278 0.28; 279 0.29; 280 0.3; 281 0.31]; %dummy array
V=X(:,2)<0.29; %logical array
dataset=A(V,:); %array with data that satisfies the given condition
filename = 'dataset.xlsx'; %excel file name
writematrix(dataset,filename,'Sheet',1) %writing dataset into excel file
You can modify the logical condition as required. Please refer these documentation on logical indexing in array and tables for more details.
Hope this helps!

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!