Excel读入Matlab函数(Excel read in a Matlab function)
我根据excel文件中数据库给出的数据定义了一个计算给定温度下相应电子密度的函数。 问题是,每次调用此函数时,它都会打开excel文件,这非常耗时。 我不想将整个数据库作为此函数的输入,我不想将
data
定义为全局,是否有人知道如何在输入的所有温度下读取这个excel文件?function [electron density] = electrondensity(temperature) data=xlsread('D:\Matlabcode\partitionfunctions.xlsx',2,'A2:D5'); ...... end
I defined a function calculating the corresponding electron density at the given temperature based on the data given by database in my excel file. The problem is that, every time this function is called, it opens the excel file, which is really time-consuming. I don't want to put the whole database as input of this function, and I do not want to define
data
as global, does anyone know how can I just read this excel file ones for all temperatures being input?function [electron density] = electrondensity(temperature) data=xlsread('D:\Matlabcode\partitionfunctions.xlsx',2,'A2:D5'); ...... end
原文:https://stackoverflow.com/questions/29609962
最满意答案
看一下sp_msforeachtable的参数。 其中一个是@replacechar,默认情况下是一个问号(即?)。 随意传递另一个同样不太可能出现在查询中的字符(可能是^)。
当然,如果我没有提到这取决于你想要做什么(我会争辩说你试图在所有桌子上做的任何东西都是这样做的话),我会失职,这样更容易在powershell中读取(和写入)解决方案:
import-module sqlps -disablenamechecking; $s = new-object microsoft.sqlserver.management.smo.server '.'; foreach ($db in $s.databases) { foreach ($table in $db.Tables) { $table | select parent, name; --merely list the table and database } }
Take a look at the parameters for sp_msforeachtable. One of them is @replacechar which, by default, is a question mark (i.e. ?). Feel free to pass in another equally unlikely character to occur in a query (maybe a ^).
Of course, I'd be remiss if I didn't mention that depending on what you're trying to do (and I would argue that anything that you're trying to do over all tables is doable this way), there are easier to read (and write) solutions in powershell:
import-module sqlps -disablenamechecking; $s = new-object microsoft.sqlserver.management.smo.server '.'; foreach ($db in $s.databases) { foreach ($table in $db.Tables) { $table | select parent, name; --merely list the table and database } }
相关问答
更多-
我可以运行查看表中是否有行的最便宜的查询是什么?(What's the cheapest query I can run to see if there are any rows in the table?)[2022-03-10]
考虑这个查询。 EXISTS将在找到第一个匹配项时停止执行。 IF EXISTS (SELECT 1 FROM MyTable) BEGIN print 'at least one!' END ELSE BEGIN print 'no rows found in table' END Consider this query. EXISTS will stop execution when it finds the first match. IF EXISTS (SELECT 1 FROM My ... -
您的查询看起来像是返回数据文件的逻辑名称而不是日志文件? (FILEID = 1) It looks like your query is returning the logical name for the data file and not the log file? (fileID=1)
-
看一下sp_msforeachtable的参数。 其中一个是@replacechar,默认情况下是一个问号(即?)。 随意传递另一个同样不太可能出现在查询中的字符(可能是^)。 当然,如果我没有提到这取决于你想要做什么(我会争辩说你试图在所有桌子上做的任何东西都是这样做的话),我会失职,这样更容易在powershell中读取(和写入)解决方案: import-module sqlps -disablenamechecking; $s = new-object microsoft.sqlserver.mana ...
-
您没有指定错误,我不确定这一点,但我猜测sys.dm_db_index_usage_stats返回相同的信息,无论您使用的是哪个数据库(服务器范围视图)。 我想你想要这样的东西...... exec sp_msforeachdb ' use [?]; IF ('[?]' NOT LIKE ''%test%'' AND EXISTS(SELECT * FROM sys.tables WHERE name LIKE ''TTT[_][a-z]%'')) BEGIN SELECT * FROM TTT_C ...
-
多个存储在同一批次中的proc调用每个都需要EXEC(UTE) EXEC sp_MSforeachdb @command1 = 'if (left(''?'', 2) = ''p_'') begin; print ''?''; end;'; EXEC sp_MSforeachdb @command1 = 'if (left(''?'', 2) = ''p_'') begin; print ''?''; end;'; 我总是使用2 x单引号而不是双引号来避免QUOTED_IDENTIFERS环境设置的问题。 ...
-
你需要添加一堆' 。 PRINT ''DROPCONSTANT @TBLNAME=''''''+PARSENAME("?",1)+'''''', @FLDNAME=''''EMAIL_S'''' '' You need to add a bunch of '. PRINT ''DROPCONSTANT @TBLNAME=''''''+PARSENAME("?",1)+'''''', @FLDNAME=''''EMAIL_S'''' ''
-
SQL2000更新: declare @s nvarchar(1000) set @s = ' and uid = ' + convert(nvarchar, user_id('my_schema')) exec sp_msforeachtable @command1='print ''?''', @whereand = @s Update for SQL2000: declare @s nvarchar(1000) set @s = ' and uid = ' + convert(nvarchar, u ...
-
你试过添加括号吗? sp_msforeachtable ' IF ''?'' <> ''[Person].[Address]'' AND ''?'' <> ''[Person].[Contact]'' AND ''?'' <> ''[Person].[CountryRegion]'' BEGIN PRINT ''?'' END '; Have you tried adding brackets? sp_msforeachtable ' IF ''?'' <> ''[Person].[Address ...
-
我会使用游标和动态SQL : --Set up for test: CREATE TABLE #DataTable (column1 nvarchar(128) NOT NULL, column2 int NOT NULL); --Create global temp table so it can be accessed from dynamic SQL. CREATE TABLE ##ActionTable ([table] nvarchar(128) NOT NULL, variable nv ...
-
sp_MSforeachdb:仅包含数据库结果的结果(sp_MSforeachdb: only include results from databases with results)[2023-03-03]
那么,首先,停止使用sp_MSforEachDb 。 哦,问题(如果你想证明,请看这里 , 这里和这里 )。 怎么样: DECLARE @cmd NVARCHAR(MAX) = N'', @sql NVARCHAR(MAX) = N''; SELECT @cmd += N'IF EXISTS (SELECT 1 FROM ' + QUOTENAME(name) + '.sys.tables WHERE name = N''Tabs'') SET @sql += N''UNION ALL ...