如果我的matrix A
大小为(500,30)
,并希望将其拆分为多个大小为(500,3)
的子矩阵,则在这种情况下为10个子矩阵。
我们如何使用内置的mat2cell
函数来实现这一目标?
我们的想法是保持子矩阵的行数与原始矩阵A
答案 0 :(得分:3)
mat2cell可以将矩阵拆分为单元格数组。
ALTER FUNCTION [dbo].[FunGetReportTRAINPDF](@StartDate nvarchar(128),
@endDate nvarchar(128),
@top INT)
RETURNS @GetAllRep TABLE
(RajaID NCHAR(50),
fk_serial NVARCHAR(50),
CircularPeriod NVARCHAR(50),
TrainNumber NVARCHAR(50),
MoveDate NVARCHAR(50),
WagonType NVARCHAR(50),
WagonTypeName NVARCHAR(50),
Degree NVARCHAR(50),
WagonNumber NVARCHAR(50),
CompartmentNumber NVARCHAR(50),
SeatNumber NVARCHAR(50),
RationCode NVARCHAR(50),
RattionName NVARCHAR(50),
SexCode NVARCHAR(50),
StartStation NVARCHAR(50),
startstationName NVARCHAR(50),
EndStation NVARCHAR(50),
EndStationName NVARCHAR(50),
TicketSeries NVARCHAR(50),
TicketNumber NVARCHAR(50),
Movetime NVARCHAR(50),
Name NVARCHAR(50),
Family NVARCHAR(50),
NationalCode NVARCHAR(50),
Fk_sellerCode NVARCHAR(50),
Fk_SaleCenterCode NVARCHAR(50),
saleCenterName NVARCHAR(50),
Telephone NVARCHAR(50),
Register NVARCHAR(50),
fk_TicketType NVARCHAR(50),
fk_Tariff NVARCHAR(50),
TariffName NVARCHAR(50),
Formula1 NVARCHAR(50),
Formula2 NVARCHAR(50),
Formula3 NVARCHAR(50),
Formula4 NVARCHAR(50),
Formula5 NVARCHAR(50),
Formula6 NVARCHAR(50),
Formula7 NVARCHAR(50),
Formula8 NVARCHAR(50),
Formula9 NVARCHAR(50),
Formula20 NVARCHAR(50),
Formula19 NVARCHAR(50),
Formula18 NVARCHAR(50),
Formula17 NVARCHAR(50),
Formula16 NVARCHAR(50),
Formula15 NVARCHAR(50),
Formula14 NVARCHAR(50),
Formula13 NVARCHAR(50),
Formula12 NVARCHAR(50),
Formula11 NVARCHAR(50),
FullPrice NVARCHAR(50),
HalfPrice NVARCHAR(50),
AxleCode NVARCHAR(50),
PathCode NVARCHAR(50),
OrderNumber NVARCHAR(50),
Formula10 NVARCHAR(50),
SaleId NVARCHAR(50),
ServicesCode NVARCHAR(50),
ServicesNo NVARCHAR(50),
ServiesAmount NVARCHAR(50),
TotalServices NVARCHAR(50),
Amount NVARCHAR(50),
ReduplicateID NVARCHAR(50),
R2 NVARCHAR(50),
[Status] NVARCHAR(50),
PersonCode NVARCHAR(50),
ReuplicateTicketNumber NVARCHAR(50),
ReuplicateTicketSeries NVARCHAR(50),
IsPrintAble NVARCHAR(50),
TrainMessage NVARCHAR(50),
CompanyName NVARCHAR(50),
Isprinted NVARCHAR(50),
statusName NVARCHAR(50),
BarcodeImage IMAGE,
SecurityNumber NVARCHAR(50),
servicetypename NVARCHAR(50),
TimeOfArrival NVARCHAR(50),
UserName NVARCHAR(50),
DateCall NVARCHAR(128),
DeparturId INT,
ReserveDate NVARCHAR(50),
IsDepartur BIT
/******[TrainReserveId] = DeparturId*********/
)
AS
BEGIN
INSERT INTO @GetAllRep
/****** Script for SelectTopNRows command from SSMS ******/
SELECT TOP (@top) [RajaID],
[fk_serial],
[CircularPeriod],
[TrainNumber],
[MoveDate],
[WagonType],
[WagonTypeName],
[Degree],
[WagonNumber],
[CompartmentNumber],
[SeatNumber],
[RationCode],
[RattionName],
[SexCode],
[StartStation],
[startstationName],
[EndStation],
[EndStationName],
[TicketSeries],
[TicketNumber],
[Movetime],
[Name],
[Family],
[NationalCode],
[Fk_sellerCode],
[Fk_SaleCenterCode],
[saleCenterName],
[Telephone],
[Register],
[fk_TicketType],
[fk_Tariff],
[TariffName],
[Formula1],
[Formula2],
[Formula3],
[Formula4],
[Formula5],
[Formula6],
[Formula7],
[Formula8],
[Formula9],
[Formula20],
[Formula19],
[Formula18],
[Formula17],
[Formula16],
[Formula15],
[Formula14],
[Formula13],
[Formula12],
[Formula11],
[FullPrice],
[HalfPrice],
[AxleCode],
[PathCode],
[OrderNumber],
[Formula10],
[SaleId],
[ServicesCode],
[ServicesNo],
[ServiesAmount],
[TotalServices],
[Amount],
[ReduplicateID],
[R2],
[Status],
[PersonCode],
[ReuplicateTicketNumber],
[ReuplicateTicketSeries],
[IsPrintAble],
[TrainMessage],
[CompanyName],
[Isprinted],
[statusName],
[BarcodeImage],
[SecurityNumber],
[servicetypename],
[TimeOfArrival],
[UserName],
[DateCall],
[DeparturId],
dbo.PersianDate([ReserveDate]),
[IsDepartur]
FROM dbo.Payments
JOIN [dbo].[TrainReportTicket] ON dbo.Payments.ObjectIdDepartue = dbo.TrainReportTicket.DeparturId
WHERE dbo.Payments.ReserveType = 2
AND dbo.Payments.Transactionsuccess = 1
AND CAST(@StartDate AS datetime) <= CAST([ReserveDate] AS datetime )
AND CAST([ReserveDate] AS datetime) <= CAST(@endDate AS datetime);
RETURN;
END;
我们可以看到mat2cell有3个参数。第一个是要分割的矩阵,第二个是行的大小,它必须与所述矩阵中的行数相加,第三个是必须与所述矩阵中的列数相加的列的大小。