Error using strcat or horzcat

5 views (last 30 days)
John Flanagan
John Flanagan on 24 Jan 2014
Answered: John Flanagan on 24 Jan 2014
I am trying to concatenate strings to allow me to read a particular row of a Excel spreadsheet.
Initially it was all done in one script and strcat worked very nicely . Using the same code in a function it did not work and gives the error below . Moreover, I tried using eval(strcat ...) and that did not work. What is it about using it in a function that is causing the trouble. I have listed the two subroutines where this is used. No error is identified in the first subroutine, although there is only one instance . The second one is giving me the trouble. Any Ideas. The goal of this is to read data from a fluorescence plate reader (Paradigm Molecular Devices) that was written by the SoftMax Pro software. The first routine unpacks the header record and the second is trying to get the data.
Error: File: Paradigm.m Line: 199 Column: 19 "strcat" previously appeared to be used as a function or command, conflicting with its use here as the name of a variable. A possible cause of this error is that you forgot to initialize the variable, or you have initialized it implicitly using load or eval.
Changing to horzcat gave the same message.
*In either case (strcat or horzcat) the error occurs in the second instance of the command in the second function. *
function Paradigm()
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
vnumber = '1.1A';
fprintf(' Paradigm FP analysis package %s \n',vnumber)
fprintf(' Matlab 2013b \n ')
fprintf(' Required packages \n')
fprintf(' Statistics Package \n')
fprintf(' \n John Flanagan \n')
fprintf(' Department of Biochmistry and Molecular Biology \n')
fprintf(' Penn State College of Medicine \n')
fprintf(' \n')
clear all; clc
% Set a default g-factor
gfactor = 1.071;
%%Get file to be opened and read.
sheet = 1; % Set sheet to read from
[filename,pathname] = uigetfile('*.*'); % GUI To get file names.
inFilePath = pathname;
inFileName = filename;
fprintf(' Path of the datafile: %s \n ',inFilePath);
fprintf(' File name of selected data file: %s \n ',inFileName)
fileread = [inFilePath,inFileName];
The majority of information about output organization is in column A. To extract it read the entire column and find the individual sections. Use this column to identify the blocks of information that the Paradigm writes to the Excel file.
[~, Endstr] = xlsread(fileread,sheet,'A:A');
%%Find the location of each of the data sets. They are marked by the
% key word Plate: in the A column.
Reads = strfind(Endstr,'Plate:');
locPlateData = find(~cellfun(@isempty,Reads));
numPlateReads = length(locPlateData);
Get all of the critical information from the first line.
iCols = zeros(2,1); iRows = zeros(2,1);
[iPlate,iAssay,iOut,~,iCols,iRows,iWells] ...
= firstRecord(fileread,locPlateData(1,1));
% Calculate some important data.
iWellsUsed = ...
(iCols(2) - iCols(1) + 1)*(iRows(2) - iRows(1) + 1);
fprintf(' The data begin in Col%u:Row%u and end at Col%u:Row%u with at total of %u Wells read. \n', ...
fprintf(' \n ');
%%PreAllocate the data vectors and get the g-factor if its in the file.
perpVec = zeros(iWellsUsed,1);
paraVec = zeros(iWellsUsed,1);
totaVec = zeros(iWellsUsed,1);
anisVec = zeros(iWellsUsed,1);
raniVec = zeros(iWellsUsed,1);
% If gfactor is stored in the file get it otherwise us the default of 1.00
if (iOut == 1) % Raw will need g-factor to process.
% Get location with g-factor data.
[gfactorR, gfactoryes, ~] = xlsread(fileread,sheet,'A25:C25');
% If cell array not empty must be g-factor.
if (~isempty(gfactoryes) && iOut(1) == 1);
gfactor = gfactorR(1); fprintf ...
(' g-factor for Raw data found in file %4.3f \n ',gfactor);
fprintf('g-factor for Raw data not found set to %4.3f \n ', ...
%%Get the data.
% TimeFormat each data in single row. iPlate = 1
% if the data is raw or both then: iOut = 1
% para = header + 2
% perp = header + 5
% reduced anisotropy = header + 8 WHEN PRESENT
% if data is in reduced format: iOut = 0
% reduced anisotropy = header + 2
% Plate format data is stored like in the plate. iPlate = 0
% if the data is raw or both then: iOut = 1
% para starts at the header + 2 then over other role 4, 6, ...
% parp = header + 3 then 5, 7, ...
% reduced anisotropy = 3rd row after the end of the perp/para
% if the data is in the reduced formation then iOut = 1;
% reduced anisotropy = header + 2.
if (iPlate == 1) % Standard read then
[paraVec, perpVec, raniVec, irani] = ...
elseif (iPlate == 0)
%[paraVec, perpVec, raniVec, irani, iWellsUsed] = ...
% plateget(fileread,locPlateData,iCols,iRows,iOut,iAssay);
disp(' This function is not currently active ');
disp(' Not a valid output format check file ')
%%This function extracts all of the relevant information from the
% first record of each data set in the Paradigm formated Excel file
function [iPlate,iAssay,iOut,nreads,Cols,Rows,nWells] ...
= firstRecord(fileread,num)
Cols = zeros(2,1); Rows = zeros(2,1);
readLoc = sprintf('%d',':','%d',num,num);
%readLoc = strcat(int2str(num),':',int2str(num));% Row containing Plate:
[ ~, ~, allread ] = xlsread(fileread,1,readLoc);% Read entire row.
% Get the data
PlateName = allread{2}; writeFormat = allread{4};
AssayType = allread{5}; ExpType = allread{6}; OutType = allread{7};
nreads = allread{9}; Cols(1) = allread{17};
Cols(2) = Cols(1) + allread{18} - 1; nWells = allread{19};
Rows(1) = allread{29}; Rows(2) = Rows(1) + allread{30} - 1;
%%Do several tests to make sure everything is Ok
% Is the data stored in Time or Plate format?
iPlate = 1;
disp(' here ');
elseif (strcmp(writeFormat,'PlateFormat'))
iPlate = 0;
disp(' Unknown format check the data file'); close;
% Is this an Endpoint or timeseries assay
if (strcmp(AssayType,'Endpoint'))
iAssay = 1;
elseif (strcmp(AssayType,'Timepoint'))
iAssay = 0;
disp(' Unknown Assay type check file or data collection '); close;
% Test to make sure that we are looking at the correct experiment.
if (~strcmp(ExpType,'Fluor Polarization'));
disp(' This is not the correct assay type check files ');
% How was it written Raw(perp/para) Reduced(anisotropy) or
% Both (perp/para/anistropy)
iOut = 1;
fprintf(' Output type is either Raw or Both \n');
elseif (strcmp(OutType,'Reduced'))
iOut = 0;
fprintf(' Output type is Reduced \n');
disp(' Incompatiable output form CHECK FILE '); close
fprintf('The Experiment is called %s. \n', PlateName);
fprintf(' It contains %s data from a %s experiment written in %s format. \n',...
function [para, perp, rani, irani] = ...
rowget(fileread, firstRow, ~, ~, ~, points, ~)
para = zeros(points,1); perp = zeros(points,1);
iCol = zeros(2,1); iRow = zeros(2,1);
rani = zeros(points,1); irani = 0;
% Set up the data type.
Last = 'CT';
First = 'C';
getdata = sprintf('C%d:CT%d', firstrow+2, firstrow+2);
% Read Perpendicular Data
[ perp, ~,~] = xlsread(fileread,sheet,getdata);
colStr = int2str(firstRow + 5);
getdata = sprintf('C%d:CT%d',First,colStr,':',Last,colStr);
% Read Parallel Data
[ para, ~,~] = xlsread(fileread,sheet,getdata);
% Test to see if both Raw and Reduced.
% If the location 2 rows down contains text information
% the curren information suggests that there is both
% else only Raw data.
colStr = int2str(firstRow + 7);
getdata = sprintf('C%d:CT%d',First,colStr,:,Last,colStr);
[~, text, ~] = xlsread(fileread,sheet,getdata);
% If there this location is not empty read in the extra data.
if (~isempty(text{1}))
irani = 1;
colStr = int2str(firstRow + 8);
getdata = sprintf('C%d:CT%d',First,colStr,':',Last,colStr);
[rani, ~, ~] = xlsread(fileread,sheet,getdata);
John Flanagan
John Flanagan on 24 Jan 2014
Edited: John Flanagan on 24 Jan 2014
Here is the code and a data file that I am trying to read. I can post the script if you like but it calls several analysis routines that I would have to upload also. The script works fine for reading the file and the analysis works great. Typically I just grab the data from the excel file and put it into the correct format etc in a new one. However, there are several students and post-docs that want to use original analysis routines and at times moving the correct data escapes them so I was trying to take that out of the equation.

Sign in to comment.

Accepted Answer

Niklas Nylén
Niklas Nylén on 24 Jan 2014
If I create one file for each of the functions (rowget.m and firstRecord.m), it seems to be working. I do not know the cause of your error but at least it is a solution.

More Answers (1)

John Flanagan
John Flanagan on 24 Jan 2014
Thanks, it works. At least after I fixed a number of stupid errors caused by my frantic attempts to debug the problem. I would really like to understand why this is a problem since for moving the code it would be better to have them all in one file, and because I would like to avoid the issue in the future.

Community Treasure Hunt

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

Start Hunting!