dealing with cell arrays

dealing with cell arrays - 14:440:127- Intro to Computers...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
14:440:127- Intro to Computers for Engineers Project 1- Dealing with Cell Arrays You've likely noticed that when Matlab reads text data from an Excel file, it reads the text data into a "Cell Array" (which we'll talk about in a later lecture). The fprintf function won't accept input from cell arrays because the cell array actually contains the string inside a cell. Here are two ways to deal with that: Option 1: (thanks to Taylor for reminding me of the easier way to deal with these) Rather than using parentheses to access elements of a cell array, you use curly braces: { }. So instead of saying fprintf(‘%s \n’, x(5,2)), use fprintf(‘%s \n’, x{5,2}) Option 2: Instead, you can "cast" (change) the cell array into a character array, which is what we've been dealing with this whole time. For a cell array stored in the variable mycellarray , you do this by typing char(mycellarray) Example: % given c, a one element cell array, and d, a one element array of numbers, just type: fprintf('first print the letters %s and then print the number %.0f \n', char(c), d)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/09/2011 for the course ENGINEERIN 127 taught by Professor Finch during the Fall '08 term at Rutgers.

Page1 / 2

dealing with cell arrays - 14:440:127- Intro to Computers...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online