MATLAB: How to display a letter in the same array as a number

asciiformatoutput

I have a 10 by 4 array that has numbers in all four rows right now. However, the fourth row is supposed to be letters. I am plugging in 'Y' and 'N' into the last row, but it changes them to the ASCII codes and returns 89 and 78 respectively.
Here's my code. The file is just a file I have stored on my computer and is not the problem.
clc;
clear;
Fid = fopen('PA_16_2_1_input.txt','r');
fgetl(Fid) % this effectively skips the first line, which has strings
A = fscanf(Fid,'%6e',[10,inf]);
fclose(Fid);
A=A';
[m,n]=size(A); % m is the number of columns, n=rows
i=1; % iteration count for outer loop (string)
while i<=n % this means that the while loop will run n times
% which is 10 for this loop
j=1; % iteration count for inner loop (bulb)
dumb=0;
v2=14400; % Voltage squared
R_tot=0;
while j<=m
s=A(j,i); % get the object from column i, row j
dumb=dumb+s;
j=j+1;
R=v2/s; % Resistance in series is v^2 over power
R=R/50; % divided by number of resistors in the circuit
R_tot=R_tot+R;
end
if dumb>2.6
w='N';
elseif dumb<2.2
w='N';
else
w='Y';
end
format shortg
b(1,i)=dumb;
b(2,i)=R_tot;
b(4,i)=w;
i=i+1;
end
disp(b)
The input looks like this.
2.4093 2.4633 2.7089 2.5957 2.308 2.1984 2.7745 2.3935 2.5827 2.5053
7.385e+05 1.0249e+06 6.0811e+05 5.9111e+05 5.7985e+05 1.9477e+06 4.3411e+05 3.5391e+06 6.4804e+05 5.1822e+05
0 0 0 0 0 0 0 0 0 0
89 89 78 89 89 78 78 89 89 89
The 89's and 78's are the problem. They should be Y and N.
Thank you for your time.

Best Answer

The only way an array can store both numbers and characters is if it is a cell array. Numeric arrays cannot store characters. You could convert the numbers to the equivalent strings and add the characters to that, for display purposes.
Related Question