Cplex-Reading Data From Excel File - excel

I have a problem where i can't load my data from EXCEL file. Here is my code,
in mod file
int i = ...;
range values = 1..i;
int storage[values] = ...;
in dat file
SheetConnection store("DataSet-5.xlsx");
storage from SheetRead(store,"'Sheet1'!B2:B201"); ##Sheet1 is the sheet name where the data is located.
i = 201;
File is in the same location as my project. But it gives Internal Error.

Related

How to write .dsv file into dynamic folders in U-SQL script

I am new to U-SQL and am trying to read multiple .dsv files from a folder and write the output as .dsv files in dynamic folder/sub folder. So far I have successfully read multiple .dsv files and am able to write the files in a single location(pre-defined location) but am not able to write the .dsv files into multiple folders/subfolders. The folders and subfolders are defined based on the file name. As an example, If the file name is ABC_20200421#015814.dsv, it should be reading data from the .dsv file and write it into folder system: test/ABC/2020/04/21/File_Data.dsv
The code I have so far is :
DECLARE #ImportFile string = "*.dsv";
-- To read all the .dsv files and move them to folder locations
DECLARE #Code String = #ImportFile.Substring(0, 3);
DECLARE #CommanName String = #ImportFile.Substring(4, 14); File_Contents
DECLARE #Year String = #ImportFile.Substring(18, 4);
DECLARE #Month String = #ImportFile.Substring(22, 2);
DECLARE #File_Date String = #ImportFile.Substring(24, 2);
#result=
SELECT col1,col2,col3
FROM Table1
//Writing to dsv file:
OUTPUT #result
TO "test/"+#Code+"/"+#Year+"/"+#Month+"/"+#File_Date+"/File_Data.dsv"
USING Outputters.Text(delimiter : '|', quoting: false);
On running the code, I get an error:
E_CSC_USER_EXPRESSIONNOTCONSTANTFOLDABLE: Expression cannot be constant folded.
Details:
at token '"/test/"', near the ###:
OUTPUT #result TO ### "/test/"+#Code+"/"+#Year+"/"+#Month+"/"+#File_Date+"/STAY_REVENUES.dsv" USING Outputters.Text(delimiter : '|', quoting : false)
Any help would be appreciated. Thanks in advance.

SAS - duplicate excel file in another folder

If i have an Excel "Covid19_report &todaysdate. &time..xlsx" file in a folder called F:\A
and I want to put this exact file into folder F:\B but duplicated 6 times like this:
"1_Covid19_report &todaysdate. &time..xlsx"
"2_Covid19_report &todaysdate. &time..xlsx"
"3_Covid19_report &todaysdate. &time..xlsx"
"4_Covid19_report &todaysdate. &time..xlsx"
"5_Covid19_report &todaysdate. &time..xlsx"
"6_Covid19_report &todaysdate. &time..xlsx"
is there a macro to do that?
The SAS function FCOPY will be helpful.
Copying binary files requires a fileref be created with options such as RECFM=N and LRECL=<filesize>
Example:
Create a sample Excel file and copy it 6 times to target files having an index prefix in their filenames.
* Create sample Excel file for copying;
ods noresults;
ods excel file='c:\temp\prices.xlsx';
proc print data=sashelp.stocks;
run;
ods excel close;
ods results;
* Copy a source file 6 times to a target file with an index number prefix name pattern;
data _null_;
length source_ref target_ref $8;
* determine name part from full pathname;
source_file = 'c:\temp\prices.xlsx';
source_name = scan(source_file,-1,'\');
* determine source file size for efficient options;
* NOTE: FCOPY only works on files < 1G in size;
rc = filename(source_ref, source_file);
fid = fopen(source_ref);
bytes = finfo(fid,'File size (bytes)');
fid = fclose(fid);
rc = filename(source_ref);
options = 'recfm=n lrecl='||trim(bytes);
* prepare SOURCE fileref;
source_ref = '';
rc = filename(source_ref, source_file, 'DISK', options);
* duplicate in same folder (via transtrn);
do index = 1 to 6;
* compute target file name and corresponding full path;
target_name = cats(index,"_",source_name);
target_file = transtrn(source_file, trim(source_name), target_name);
* create temporary TARGETR fileref (due to ref value passed in being blank);
target_ref = '';
if 0 = filename (target_ref, target_file, 'DISK', options) then do;
rc = fcopy ('source', target_ref);
rc = filename(target_ref); * clear TARGET fileref;
end;
end;
stop;
run;
i tried doing this, but do not work:
%let todaysDate = %sysfunc(today(), yymmdd10.); %put &todaysDate;
data _null_; ftime = intnx('hour',time(),0,'b'); cftime =
compress(put(ftime,hhmm.),":"); call symputx("ftime",cftime); run;
%put &=ftime.;
%let path = F:\A;
%let file = COVID-19 Report &todaysdate. &ftime.;
filename source "&path.\&file.";
data _null_; length target_ref $8;
do index = 1 to 6;
target_file = cats("&path.",index,"_&file.");
target_ref = '';
* create temporary fileref (due to initial ref value being blank);
if 0 = filename (target_ref, target_file) then do;
rc = fcopy ('source', target_ref);
rc = filename(target_ref);
end; end; stop; run;

How to save data in excel file MATLAB?

I want to save pitch,yaw and roll data in excel file for all frames. Eg: if i have 200 frames then i want to save 200 frames information in excel file. I have tried but my code only stores one frame data.exceldata
fitting_model='models/Chehra_f1.0.mat';
load(fitting_model);
mov=VideoReader('7_a.avi'); %Read video file and create an object
c=mov.NumberOfFrames;
for k=1:c
a = read(mov, k);
img=im2double(a);
disp(['Detecting Face in ']);
faceDetector = vision.CascadeObjectDetector(); % detect face in an image
bbox = step(faceDetector, img); %create boundary box around face
test_init_shape = InitShape(bbox,refShape); %initialize facial points in variable
test_init_shape = reshape(test_init_shape,49,2);
if size(img,3) == 3
test_input_image = im2double(rgb2gray(img));
else
test_input_image = im2double((img));
end
disp(['Fitting']);
MaxIter=6;
test_points = Fitting(test_input_image,test_init_shape,RegMat,MaxIter);
load('3D_Shape_Model.mat');
n=49;
test_image=img;
imshow(test_image);hold on;
% % Compute 3D Head Pose
if(n==49)
test_shape=test_points;
[pitch,yaw,roll] = ComputePose(PDM_49,test_shape(:));
filename='framesdata.xlsx';
header = {'Pitch', 'yaw ','roll'};
new_data = num2cell([pitch(:), yaw(:), roll(:)]);
output = [header; new_data];
xlswrite(filename,output);
end
plot(test_shape(:,1),test_shape(:,2),'b*');
title([num2str(i),' : Pitch = ',num2str(pitch),' ; Yaw = ',num2str(yaw),' ; Roll = ',num2str(roll)]);
set(gcf,'units','normalized','outerposition',[0 0 1 1]);
pause(0.5);
close all;
end
As #excaza stated, you will need to move the xlswrite command out of your loop or specify the cells you are writing. Please see the xlswrite Doc for more information. The correct syntax would be :
xlswrite(filename,A,xlRange)
The following is the example they provide:
filename = 'testdata.xlsx';
A = {'Time','Temperature'; 12,98; 13,99; 14,97};
sheet = 2;
xlRange = 'E1';
xlswrite(filename,A,sheet,xlRange)
You will just need to provide xlswrite the address to start writing data.

Writing data to excel files, MATLAB

I am using MatlabR2011a on my Windows 7 machine.
I have a folder of 635 text files. Each file contains multiple rows and 2 columns. I am trying to loop through the folder and read each file and write these values to excel. So far this is what I have:
close all; clc;
dirname = uigetdir;
Files = dir(fullfile(dirname,'*.txt'))
for k = 1:635
j =1
filename = fullfile(dirname,Files(k).name);
fid = fopen(filename);
x = fgetl(fid)
while ischar(x)
x = fgetl(fid)
a2 = strtrim(x);
a3 = textscan(a2,'%s');
a4 = a3{1}{1};
a5= a3{1}{2};
pos3 = strcat('A',num2str(j));
xlswrite('sample_output',{a4,a5},'Sheet1',pos3)
j = j+1;
end
fclose(fid);
end
It keeps giving me the following error after finishing reading the first file.
Error using ==> strtrim Input should be a string or a cell array of strings.
A sample input file looks like this:
15076 4636259
15707 4636299
15714 1781552
15721 4204950
15730 2174919
16209 4636510
16413 4758572
16470 4445808
17519 311397
17667 2116489
17739 1729694
18024 3210756
18627 3714194
18695 4192858
19141 632766
19318 1923574
19438 1255216
19493 4635020
19771 4770250
How can I fix this? Would appreciate help with this!
In the while loop, cut the line
x=fgetl(fid)
...and paste it before the end statement right after j=j+1.
The error occurs because you get a line before the while statement, then you use the while statement to test validity of the string (all fine so far), but then immediately get the subsequent line before you perform your string operation. The call to fgetl at the start of the while block could return an EOF, causing subsequent string manipulation functions to fail.
Also... The code would be more robust if you set your for loop like so
for k=1:numel(Files)
Since all your data are numeric this should work. Give it a try.
dirname = uigetdir;
Files = dir(fullfile(dirname,'*.txt'))
j =0;
for k = 1:numel(Files)
filename = fullfile(dirname,Files(k).name);
x = dlmread(filename,'\t'); %# I assume tab-delimiter
j = j + size(x, 1);
xlswrite( 'sample_output', x, 'Sheet1',sprintf('A%d',j) )
end

Batch modifying xls files and save it as txt file in matlab

I have a code which reads a an excel file and modifies the xls fil and then save it as an text file
[f,n] = uigetfile('*.xls');
[num,text,row]=xlsread(f);
data=num';
temp_dir = pwd;
[f,n]=uiputfile('*.txt');
if isstr(f)
cd(n);
fid=fopen(f,'w');
[rows,cols]=size(text);
for i=1:rows
fprintf(fid,'%s\t',text{i,1:end-1});
fprintf(fid,'%s\n',text{i,end});
end
plats = '%10f\t';
[rows,cols] = size(data);
for n = 1:rows-2
plats = [plats,'%10f\t'];
end
now I have like 100 xls file and I want to this process for all of them like batch processing.
I know that I could use :
files_from= dir(fullfile(from_dir,'*.xls'));
for i = 1:length(files_from)
FileName=files_from(i).name;
[num,txt,all]= xlsread(fullfile(from_dir,FileName));
xlswrite(fullfile(to_dir, files_from(i).name),data);
end
but I can't get it write :((((((((
please any suggestion?????

Resources