Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Reading in matrix (non-structured) with fscanf-empty input?

Subject: Reading in matrix (non-structured) with fscanf-empty input?

From: Stan

Date: 7 Sep, 2013 19:42:09

Message: 1 of 1

Hello,

I have written output (numeric only) to a text file as follows:

fmt2=['%8s' '%4.f%4.f%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d\n'];

sav_fid2 = fopen('Names2.txt', 'wt');
for jkl = 1:cnf
     fprintf(sav_fid2,fmt2, 'stage_1.txt', xy(jkl,:),sum(data(ROI1,jkl+1)),sum(data(ROI2,jkl+1)),sum(data(ROI3,jkl+1)),sum(data(ROI4,jkl+1)),sum(data(ROI5,jkl+1)),sum(data(ROI6,jkl+1)),sum(data(ROI7,jkl+1)),sum(data(ROI8,jkl+1)),sum(data(ROI9,jkl+1)),sum(data(ROI10,jkl+1)),sum(data(ROI11,jkl+1)),sum(data(ROI12,jkl+1)),sum(data(ROI13,jkl+1)),sum(data(ROI14,jkl+1)),sum(data(1:end,jkl+1)));
end

fclose(sav_fid2);

Now, I need to read in those numbers (as a matrix), multiply them by 256 and then print the matrix (after multiplication) to a different text file. I tried this:

clear
clc
fmt2=['%8s' '%4.f%4.f%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d\n'];
fid = fopen(''stage_1.txt'', 'wt');
num_t = fscanf(fid, fmt2);
fclose(fid);

I am getting:
num_t =

     ''
Is there a mistake with the format used to read the pattern with fscanf? Is fscanf the most appropriate way to read in these numbers?

* the number 256 will change from file to file. I can handle that part of the code. For the purposes of this example, we can assume that 256 is a constant.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us