i have some problems with rowspan:
var doc1 = new Document();
doc1.SetPageSize(PageSize.A4.Rotate());
string path = Server.MapPath("PDFs");
PdfWriter.GetInstance(doc1, new FileStream(path + "/Doc1.pdf", FileMode.Create));
doc1.Open();
PdfPTable table = new PdfPTable(17);
PdfPCell cell = new PdfPCell(new Phrase("Missioni aggregato per macro causali"));
cell.Colspan = 17;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Matricola"));
cell.Rowspan = 2;
cell.Rotation = 90;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Nominativo"));
cell.Rowspan = 2;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Assegnazione"));
cell.Colspan = 2;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Riepilogo missioni valori dal "));
cell.Colspan = 13;
cell.Rowspan = 2;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Struttura"));
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Ufficio"));
table.AddCell(cell);
the cell "Riepilogo missioni valori dal " is in the same row of cell "struttura" and cell "ufficio"
Why?
how can i do?
thanks
Your cell "Riepilogo missioni valori dal " only spans 13 columns. PdfPTable requires that you fill in the rest of those columns (4) at the end of your current row before it will jump to the next row of 17 columns.
To fill in the end of your row, you can either add 4 empty cells or use the CompleteRow method.
table.AddCell("")
table.AddCell("")
table.AddCell("")
table.AddCell("")
or
table.CompleteRow()
Related
I Want to select a row or column of a table with the edit field component and do some actions on these data and show the result in the first cell of table ([1,1])
rowNames={1:100}
columnName={A:ZZ}
like this:
sum(A1:A20) or Max(AA5:AA10)
I want to write above order in the edit field component
and show the result of them in cell[A,1]
How can I do that?
Here's an implementation that might be similar to what you are attempting to achieve.
Any subset can be calculated using the command such as: Sum(A1:A2)U(B2:B3)
Where A indicates the columns apart of the set and B indicates the rows apart of the set.
Some more test functions include:
Sum(A1:A4) and
Sum(B1:B4)
%Random data%
global Data;
Data = [1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4];
%Converting data into table%
Data = array2table(Data);
%Grabbing the size of the data%
[Number_Of_Rows, Number_Of_Columns] = size(Data);
%Creating arrays for setting the row and column names%
Row_Labels = strings(1,Number_Of_Rows);
Column_Labels = strings(1,Number_Of_Columns);
for Row_Scanner = 1: +1: Number_Of_Rows
Row_Labels(1,Row_Scanner) = ["B" + num2str(Row_Scanner)];
end
for Column_Scanner = 1: +1: Number_Of_Columns
Column_Labels(1,Column_Scanner) = ["A" + num2str(Column_Scanner)];
end
Row_Labels = cellstr(Row_Labels);
Column_Labels = cellstr(Column_Labels);
%UItable%
Main_Figure = uifigure;
Table = uitable(Main_Figure,'Data',Data);
Table.ColumnName = Column_Labels;
Table.RowName = Row_Labels;
set(Table,'ColumnEditable',true(1,Number_Of_Columns))
%Callback function to update the table%
% Table.CellEditCallback = #(Table,event) Update_Table_Data(Table);
%UIeditfield%
Selection_Field = uieditfield(Main_Figure,'text');
Field_Height = 20;
Field_Width = 100;
X_Position = 350;
Y_Position = 200;
Selection_Field.Position = [X_Position Y_Position Field_Width Field_Height];
Result_Label = uilabel(Main_Figure);
Result_Label.Position = [X_Position Y_Position-100 Field_Width Field_Height];
Selection_Field.ValueChangedFcn = #(Selection_Field,event) Compute_Value(Table,Selection_Field,Result_Label);
%Computing value
function [Data] = Compute_Value(Table,Selection_Field,Result_Label)
Data = Table.Data;
User_Input_Function = string(Selection_Field.Value);
Function = extractBefore(User_Input_Function,"(");
% fprintf("Function: %s \n",Function);
Key_Pairs = extractBetween(User_Input_Function,"(",")");
% fprintf("Key Pairs: (%s)\n", Key_Pairs);
Key_1 = extractBefore(Key_Pairs(1,1),":");
Key_2 = extractAfter(Key_Pairs(1,1),":");
Key_1
Key_2
if length(Key_Pairs) == 2
Key_3 = extractBefore(Key_Pairs(2,1),":");
Key_4 = extractAfter(Key_Pairs(2,1),":");
Key_3
Key_4
end
%Exracting the letters of each key
if contains(Key_1, "A") == 1
% fprintf("Function on columns\n")
Minimum_Column = str2num(extractAfter(Key_1,"A"));
Maximum_Column = str2num(extractAfter(Key_2,"A"));
Table_Subset = Data(1,Minimum_Column:Maximum_Column);
end
if contains(Key_1, "B") == 1
% fprintf("Function on rows\n")
Minimum_Row = str2num(extractAfter(Key_1,"B"));
Maximum_Row = str2num(extractAfter(Key_2,"B"));
Table_Subset = Data(Minimum_Row:Maximum_Row,1);
end
if length(Key_Pairs) == 2
Minimum_Column = str2num(extractAfter(Key_1,"A"));
Maximum_Column = str2num(extractAfter(Key_2,"A"));
Minimum_Row = str2num(extractAfter(Key_3,"B"));
Maximum_Row = str2num(extractAfter(Key_4,"B"));
Table_Subset = Data(Minimum_Row:Maximum_Row,Minimum_Column:Maximum_Column);
end
Table_Subset = table2array(Table_Subset);
%Statements for each function%
if (Function == 'Sum' || Function == 'sum')
fprintf("Computing sum\n");
Result_Sum = sum(Table_Subset,'all');
Result_Sum
Result_Label.Text = "Result: " + num2str(Result_Sum);
end
if (Function == 'Max' || Function == 'max')
fprintf("Computing maximum\n");
Result_Max = max(Table_Subset);
Result_Max
Result_Label.Text = "Result: " + num2str(Result_Max);
end
if (Function == 'Min' || Function == 'min')
fprintf("Computing minimum\n");
Result_Min = min(Table_Subset);
Result_Min
Result_Label.Text = "Result: " + num2str(Result_Min);
end
end
I have an image divided into 16x16 blocks, where each block are like an array. How can I convert each block as an image?
My code is:
I=imread(image);
img=rgb2gray(I);
[col, row] = find(img<250);
imout = I(min(col):max(col), min(row):max(row));
imshow(imout);
[rows columns numberOfBands]=size(imout);
blockSizeR = 16;
blockSizeC = 16;
wholeBlockRows = floor(rows / blockSizeR);
wholeBlockCols = floor(columns / blockSizeC);
blockNumber=1;
for row = 1 : blockSizeR : rows
for col = 1 : blockSizeC : columns
row1 = row;
row2 = row1 + blockSizeR - 1;
row2 = min(rows, row2);
col1 = col;
col2 = col1 + blockSizeC - 1;
col2 = min(columns, col2);
block=imout(row1:row2, col1:col2);
subplot(16,16,blockNumber);
imshow(block);
blockNumber = blockNumber + 1;
end
end
To create an image file with an array, you should use the built-in imwrite function.
Here is a piece of code that does pretty much the same as what you already do, plus saving it into files:
% ...
% imout contains the image to split
n = 16;
% Divide into nxn images
s1 = [n*ones(1,floor(size(imout,1)/n)) mod(size(imout,1),n)];
s2 = [n*ones(1,floor(size(imout,2)/n)) mod(size(imout,2),n)];
C = mat2cell(imout, s1, s2);
% Save into files
outpref = '/your/path/img_';
outsuff = '.png';
[I, J] = meshgrid(1:numel(s1), 1:numel(s2));
cellfun(#(x,i,j) imwrite(x, [outpref num2str(i) '_' num2str(j) outsuff]), C, num2cell(I'), num2cell(J'));
How to write the cell as below in text file(my_data.out)?
http_only = cell2mat(http_only)
dlmwrite('my_data.out',http_only)
I get the error as below:(I have tried to solve but still return me the error)
Here is my full code:
I want to generate the text file for each of the data which only store 'http_only'
then check for that is it meet the word in split_URL.
%data = importdata('DATA/URL/training_URL')
data = importdata('DATA/URL/testing_URL')
domain_URL = regexp(data,'\w*://[^/]*','match','once')
no_http_URL = regexp(domain_URL,'https?://(?:www\.)?(.*)','tokens','once');
no_http_URL = vertcat(no_http_URL{:});
split_URL = regexp(no_http_URL,'[:/.]*','split')
[sizeData b] = size(split_URL);
for i = 1:100
A7_data = split_URL{i};
data2=fopen(strcat('DATA\WEBPAGE_SOURCE\TESTING_DATA\',int2str(i),'.htm'),'r')
CharData = fread(data2, '*char')'; %read text file and store data in CharData
fclose(data2);
img_only = regexp(CharData, '<img src.*?>', 'match'); %checking
http_only = regexp(img_only, '"http.*?"', 'match');
http_only1 = horzcat(http_only{:});
fid = fopen('my_data.out',int2str(i),'w');
for col = 1:numel(http_only1)
fprintf(fid,'%s\n',http_only1{:,col});
end
fclose(fid);
feature7_data=(~cellfun('isempty', regexpi(CharData , A7_data, 'once')))
B7(i)=sum(feature7_data)
end
feature7(B7>=5)=-1;
feature7(B7<5&B7>2)=0;
feature7(B7<=2)=1;
feature7'
Write cell-by-cell using fprintf -
fid = fopen('my_data.out','w');
for col = 1:numel(http_only)
fprintf(fid,'%s\n',http_only{:,col});
end
fclose(fid);
Edit 1: If your input is a cell array of cell arrays, use this code instead.
Code
http_only1 = horzcat(http_only{:});
fid = fopen('my_data.out','w');
for col = 1:numel(http_only1)
fprintf(fid,'%s\n',http_only1{:,col});
end
fclose(fid);
Edit 2: For a number of inputs to be stored into separate files, use this demo -
data1 = {{'[]'} {'"http://google.com"'} {'"http://yahoo.com'}};
data2 = {{'[]'} {'"http://overflow.com"'} {'"http://meta.exchange.com'}};
data = cat(1,data1,data2);
for k = 1:size(data,1)
data_mat = horzcat(data{k,:});
out_filename = strcat(out_basename,num2str(k),'.out');
fid = fopen(out_filename,'w');
for col = 1:numel(data_mat)
fprintf(fid,'%s\n',data_mat{:,col});
end
fclose(fid);
end
num2 = xlsread('CANCER.xls','C2:C102')
[IDX,C1] = kmeans(num2,2)
num3 = xlsread('CANCER.xls','C103:C203')
[IDX,C2] = kmeans(num3,2)
num4 = xlsread('CANCER.xls','C304:C404')
[IDX,C3] = kmeans(num4,2)
num5 = xlsread('CANCER.xls','C405:C505')
[IDX,C4] = kmeans(num5,2)
num6 = xlsread('CANCER.xls','C506:C606')
[IDX,C5] = kmeans(num6,2)
num7 = xlsread('CANCER.xls','C607:C707')
[IDX,C6] = kmeans(num7,2)
num8 = xlsread('CANCER.xls','C708:C808')
[IDX,C7] = kmeans(num8,2)
num9 = xlsread('CANCER.xls','C809:C909')
[IDX,C8] = kmeans(num9,2)
num10 = xlsread('CANCER.xls','C1000:C1099')
[IDX,C9] = kmeans(num10,2)
num11= xlsread('CANCER.xls','C1100:C1199')
[IDX,C10] = kmeans(num11,2)
num12= xlsread('CANCER.xls','C1200:C1299')
[IDX,C11] = kmeans(num12,2)
num13= xlsread('CANCER.xls','C1300:C1399')
[IDX,C12] = kmeans(num13,2)
num14= xlsread('CANCER.xls','C1400:C1499')
[IDX,C13] = kmeans(num14,2)
kmns=[C1;C2;C3;C4;C5;C6;C7;C8;C9;C10;C11;C12;C13;C14]
Try this -
%%// Start and stop row numbers
start_ind = [2 103 304 405 506 607 708 809 1000 :100: 1400];
stop_ind = [start_ind(1:8)+100 start_ind(9:end) + 99];
data = xlsread('CANCER.xls'); %%// Read data in one-go
C = zeros(2,numel(start_ind)); %%// Place holder for C values
for k1 = 1:numel(start_ind)
num = data(start_ind(k1):stop_ind(k1),3); %%// Data for the specified range
[IDX,C(:,k1)] = kmeans(num,2); %%// Do the calculations
end
kmns = reshape(C,[],1); %%// Final result
I'm getting real pissed because of a problem that I know for a fact that isn't on my end! Every time I run my current project in Eclipse, the display is different every time!
I mean, I run it once and it shows only three of my components.
I run it again and it shows more.
I run it again and it shows three
etc..
What the hell is going on. This is the code I'm running in a main string args:
JFrame frame = new JFrame("Survey");
frame.setSize(500, 500);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new GridBagLayout());
panel.setBackground(Color.GRAY);
frame.add(panel, BorderLayout.NORTH);
GridBagConstraints c = new GridBagConstraints();
JLabel label1 = new JLabel("First name:");
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(5, 5, 5, 5);
panel.add(label1, c);
JLabel label2 = new JLabel("Last name:");
c.gridx = 0;
c.gridy = 1;
panel.add(label2, c);
JTextField text1 = new JTextField(10);
c.gridx = 1;
c.gridy = 0;
panel.add(text1, c);
JTextField text2 = new JTextField(10);
c.gridx = 1;
c.gridy = 1;
panel.add(text2, c);
JLabel label3 = new JLabel("What is your favorite sport:");
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 2;
panel.add(label3, c);
String[] combobox = {"Basketball", "Soccor", "Other"};
JComboBox cbx = new JComboBox(combobox);
cbx.setPreferredSize(new Dimension(150, 20));
c.gridx = 0;
c.gridy = 3;
panel.add(cbx, c);
JLabel label4 = new JLabel("Comments about yourself:");
c.gridx = 0;
c.gridy = 4;
panel.add(label4, c);
JTextArea area = new JTextArea();
area.setPreferredSize(new Dimension(185, 100));
c.gridx = 0;
c.gridy = 5;
c.gridheight = 5;
panel.add(area, c);
JButton submit = new JButton("Submit");
submit.setPreferredSize(new Dimension(20, 20));
c.gridx = 0;
c.gridy = 6;
panel.add(submit, c);
Revalidate is not needed at all. Make sure you properly create your components on EDT thread and you'll have no such problems anymore. Check out the following article http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html