MATLAB中 怎样让两个M文件相关联着一起运行?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MATLAB中 怎样让两个M文件相关联着一起运行?相关的知识,希望对你有一定的参考价值。
一个M文件中有定义函数 function 的语句 这是不能在命令窗口里运行的对吧?
另一个M文件里有这个函数的用法 单运行一个M文件是不对的 老师让两个都运行?怎么办?不胜感激啊!!!
对不起!看得不是很懂?!
Run utility to associate files with .fig extension with MATLAB Run utility to associate files with .m extension with MATLAB Run utility to associate files with .mat extension with MATLAB Run utility to associate files with .mdl extension with MATLAB Run utility to associate MATLAB with MEX-files Run utility to associate MATLAB with P-files Run utility to associate MATLAB with all of these file types: FIG, M, MAT, MDL, MEX, and P 参考技术A 你把自定义函数的M文件放在Matlab路径里,这样系统能够找到,这样就可以了追问
谢谢您的回答 可是对不起 还是不懂。。。
追答你这样做,新建一个M文件,然后把内容复制进去,其中函数那个文件名要和函数名一致,保存在默认路径里。你再试试
追问谢谢您!我试过了 可是有错误 A function declaration cannot appear within a script M-file.
这是怎么回事啊?谢谢!!!
再看看别人怎么说的。
我怎样才能让苦艾酒和 Dataloader 一起工作?
【中文标题】我怎样才能让苦艾酒和 Dataloader 一起工作?【英文标题】:How can I get Absinthe and Dataloader to work together? 【发布时间】:2021-02-25 18:23:36 【问题描述】:我有一个 GraphQL api,它使用传统的解析函数可以正常工作。我的目标是消除 N+1 问题。
为此,我决定使用 Dataloader。我已经完成了这些步骤,应该让应用程序运行:
-
我将这两个函数添加到我的上下文模块中:
defmodule Project.People do
# CRUD...
def data, do: Dataloader.Ecto.new(Repo, query: &query/2)
def query(queryable, _params) do
queryable
end
end
-
我在 Schema 模块中添加了
context/1
和 plugins/0
并更新了查询解析器:
defmodule ProjectWeb.GraphQL.Schema do
use Absinthe.Schema
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias ProjectWeb.GraphQL.Schema
alias Project.People
import_types(Schema.Types)
query do
@desc "Get a list of all people."
field :people, list_of(:person) do
resolve(dataloader(People))
end
# Other queries...
end
def context(context) do
loader =
Dataloader.new()
|> Dataloader.add_source(People, People.data())
Map.put(context, :loader, loader)
end
def plugins, do: [Absinthe.Middleware.Dataloader | Absinthe.Plugin.defaults()]
end
官方教程中没有给出其他步骤。我的:person
对象如下所示:
@desc "An object that defines a person."
object :person do
field :id, :id
field :birth_date, :date
field :first_name, :string
field :last_name, :string
field :pesel, :string
field :second_name, :string
field :sex, :string
# field :addresses, list_of(:address) do
# resolve(fn parent, _, _ ->
# addresses = Project.Repo.all(Ecto.assoc(parent, :addresses))
# :ok, addresses
# end)
# description("List of addresses that are assigned to this person.")
# end
# field :contacts, list_of(:contact) do
# resolve(fn parent, _, _ ->
# contacts = Project.Repo.all(Ecto.assoc(parent, :contacts))
# :ok, contacts
# end)
# description("List of contacts that are assigned to this person.")
# end
end
注释部分是在没有数据加载器的情况下工作并且不会导致问题的解析器。
当我尝试查询时:
people
id
我明白了:
Request: POST /graphiql
** (exit) an exception was raised:
** (Dataloader.GetError) The given atom - :people - is not a module.
This can happen if you intend to pass an Ecto struct in your call to
`dataloader/4` but pass something other than a struct.
我没有完全理解错误消息,因为我确实将一个模块传递给了dataloader/1
,但我找不到解决方案。可能是什么情况?
【问题讨论】:
【参考方案1】:我已经设法让它工作了——方法如下:
数据加载器本身并不知道从数据库中提取什么,它只了解关联。因此dataloader(People)
只能是object
块的一部分,而不是query
块的一部分。
换句话说:
defmodule ProjectWeb.GraphQL.Schema do
use Absinthe.Schema
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias ProjectWeb.GraphQL.Schema
alias Project.People
import_types(Schema.Types)
query do
@desc "Get a list of all people."
field :people, list_of(:person) do
resolve(&StandardPerson.resolver/2)
end
# Other queries...
end
def context(context) do
loader =
Dataloader.new()
|> Dataloader.add_source(People, People.data())
Map.put(context, :loader, loader)
end
def plugins, do: [Absinthe.Middleware.Dataloader | Absinthe.Plugin.defaults()]
end
和
@desc "An object that defines a person."
object :person do
field :id, :id
field :birth_date, :date
field :first_name, :string
field :last_name, :string
field :pesel, :string
field :second_name, :string
field :sex, :string
field :addresses, list_of(:address) do
resolve(dataloader(People))
description("List of addresses that are assigned to this person.")
end
field :contacts, list_of(:contact) do
resolve(dataloader(People))
description("List of contacts that are assigned to this person.")
end
end
【讨论】:
以上是关于MATLAB中 怎样让两个M文件相关联着一起运行?的主要内容,如果未能解决你的问题,请参考以下文章